1

I'm stuck here with an error in my Ada program. There is a lot of code and I don't want to copy all of it here, so I hope that the part that I'm sharing is the part from where the problem comes.

   task type Producent is
       entry Start(Jedzenie: in Typ_Jedzenia; Czas_Produkcji: in Integer);
   end Producent;

   task type Buffer is
       entry Zamow(Jedzenie: in Typ_Jedzenia; Numer: in Integer; Czy_Zatwierdzono: out Boolean);
       entry Dostarcz(Zamowienie: in Typ_Zestawu; Numer: out Integer);
   end Buffer;


task body Producent is
  package Losowa_Produkcja is new
    Ada.Numerics.Discrete_Random(Zakres_Czasu_Produkcji);
  Generator: Losowa_Produkcja.Generator;
  Index_Jedzenia: Integer;
  Nr_Produkcji_Jedzenia: Integer := 1;
  Produkcja: Integer;
  Zatwierdzono: Boolean := False;
  
begin
  accept Start (Jedzenie : in Typ_Jedzenia; Czas_Produkcji : in Integer) do
     Losowa_Produkcja.Reset(Generator);
     Index_Jedzenia := Jedzenie;
     Produkcja := Czas_Produkcji;
  end Start;
    
  loop
     delay Duration(Losowa_Produkcja.Random(Generator));
     Put_Line("Przygotowano " & Nazwa_Jedzenia(Index_Jedzenia) & " numer " & Integer'Image(Nr_Produkcji_Jedzenia));
     
     loop
        Buffer.Zamow(Index_Jedzenia, Nr_Produkcji_Jedzenia, Zatwierdzono); <-------- ERROR
        if Zatwierdzono = False then
           Put_Line("Brak miejsca w kuchni dla " & Nazwa_Jedzenia(Index_Jedzenia) & ". Wstrzymanie");
           delay Duration(3.0);
        else
           Nr_Produkcji_Jedzenia := Nr_Produkcji_Jedzenia + 1;
        end if;
        exit;
     end loop;
  end loop;
end Producent;

task body Buffer is
  begin
  Put_Line("Jestesmy u Buffera");
  loop
     select
        accept Zamow(Jedzenie: in Typ_Jedzenia; Numer: in Integer; Czy_Zatwierdzono: out Boolean) do
           Put_Line("Trwa zamawianie...");
        end Zamow;
     end select;
  end loop;
end Buffer;

From my attempts I understand that when I want to call entry Buffer.Zamow(Index_Jedzenia, Nr_Produkcji_Jedzenia, Zatwierdzono); (which is in task Producent) there is an error with 'Zatwierdzono' argument. When I removed this argument from declarations and definitions Zamow() entry worked.

Full error: invalid use of subtype mark in expression or call

What should I change or where is the problem with this boolean Zatwierdzono variable? Zatwierdzono means Accepted in this case. Thanks for any ideas.

4
  • 2
    Possibly relevant : there would appear to be a type mismatch on the first parameter of that entry call. But as mwe don't have the full code or the fuss error message (which would include line:character and possibly other information, anything more is guesswork. Try making a minimal testcase... Commented Oct 6, 2020 at 20:08
  • 1
    At the point of the call (Buffer.Zamow) that is giving you the error, the only thing visible named Buffer is a type: task type Buffer. You cannot call a type. You need a task which is an object of the type (O : Buffer;) and then you can call the entries of that task: O.Zamow. Commented Oct 7, 2020 at 6:34
  • Or maybe you don’t need task types? How many instances will there be? task Buffer is ... Commented Oct 7, 2020 at 12:50
  • Thank you @JeffreyR.Carter, that was it. I haven't seen earlier that I'm trying to call an entry for a task type, not an object of this type. Mixed names... Thanks again so much! Commented Oct 7, 2020 at 13:12

1 Answer 1

4

You have two problems:

Index_Jedzenia := Jedzenie;

In your Start entry is trying to implicitly convert Jedzenie from its type, Typ_Jedzenia, to Integer, the type of Index_Jedzenia. You need some way to convert this.

Additionally on the line you are seeing the error on, the first parameter of that entry is of type Typ_Jedzenia but you are passing in an Integer (Index_Jedzenia is an integer). Again, you can't implicitly convert types like that.

If Typ_Jedzenia is actually an integer, you can explicitly convert them. Otherwise you need to make a conversion function of some type and use that before passing in or assigning to different types.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you :) I mixed task type name with task type object name and that was the main problem, the conversion is another thing but I've handled it somehow. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.