1

I'm trying to make a simple looping program but get the error on line 18, subtype mark required in this context, but I don't get this error when running other programs?

with Ada.Text_IO;
use Ada.Text_IO;

with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

with Ada.Strings.Unbounded;
use Ada.Strings.Unbounded;

with Ada.Text_IO.Unbounded_IO;
use Ada.Text_IO.Unbounded_IO;

procedure main is
input   : Unbounded_String;

begin

    while input not in "!Close" loop --Line 18
    Get_Line(input);
end loop;

end main;
Bliwiker
  • 15
  • 3
  • 3
    Back in the Good Old Days, all membership tests had the form ` in `, which is where this error message comes from. Now membership tests are more complex, but GNAT's error msg hasn't kept up. – Jeffrey R. Carter May 30 '18 at 08:43

1 Answers1

3

In a membership test, both values must be of the same type. In your case, input is an Unbounded_String, while "!Close" is a string literal. You either have to convert one of them into the other, or just use the equality operator defined in Ada.Strings.Unbounded (And since you've already done use Ada.Strings.Unbounded you have visibility of all the alternatives):

while input not in To_Unbounded_String("!Close") loop --Line 18

or

while To_String(input) not in "!Close" loop --Line 18

or

while input /= "!Close" loop --Line 18
egilhh
  • 6,464
  • 1
  • 18
  • 19
  • Thank you so much! – Bliwiker May 30 '18 at 09:43
  • The first two versions may work, but to me they look completely bizarre! And isn’t a type conversion needed for the third version? – Simon Wright May 30 '18 at 19:11
  • The first two is allowed in Ada 2012, see [AI05-0158](http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ai05s/ai05-0158-1.txt?rev=1.20). In the case above, the membership_choice_list contains only one value, which I guess may look weird. The last one uses the equals operator defined in Ada.Strings.Unbounded, `function "=" (Left : in Unbounded_String; Right : in String) return Boolean;` – egilhh May 31 '18 at 06:47