A user recently posted a question, and deleted it (perhaps because we were less than welcoming). Effectively, this was the problem: compiling with gnatmake -gnatwl person_1.adb
, the result was
1. with Ada.Text_IO; use Ada.Text_IO;
2. with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
3. procedure Person_1 is
4. type String is
5. array (Positive range <>) of Character;
6. S: String (1..10);
7. begin
8. Put("Write a name: ");
9. Get(S);
1 6
>>> no candidate interpretations match the actuals:
>>> missing argument for parameter "Item" in call to "Get" declared at a-tiinio.ads:90, instance at a-inteio.ads:18
>>> missing argument for parameter "Item" in call to "Get" declared at a-tiinio.ads:51, instance at a-inteio.ads:18
>>> missing argument for parameter "Item" in call to "Get" declared at a-textio.ads:451
>>> missing argument for parameter "Item" in call to "Get" declared at a-textio.ads:378
>>> expected type "Standard.Integer"
>>> found type "String" defined at line 4
>>> ==> in call to "Get" at a-tiinio.ads:59, instance at a-inteio.ads:18
>>> ==> in call to "Get" at a-textio.ads:454
>>> ==> in call to "Get" at a-textio.ads:381
10. end Person_1;
which is quite confusing. What’s going on?
The trouble is, this code defines its own type String
, which hides the standard type String
. Ada.Text_IO.Get
expects a parameter of the standard String
type, but it’s actually been given a parameter of the local String
type.
The Ada Wikibook says, under the bullet point Name Equivalence,
Two types are compatible if and only if they have the same name; not if they just happen to have the same size or bit representation. You can thus declare two integer types with the same ranges that are totally incompatible, or two record types with exactly the same components, but which are incompatible.
But, these two types do have the same name! (String
). Don’t they?
The reason that they don’t, after all, is that the fully qualified names are actually different. Get
expects Standard.String
(ARM A.1(37)), but the local version is Person_1.String
.
You might have hoped that -gnatwh
(turn on warnings for hiding declarations) would report this, but unfortunately not.
I’m not sure why the compiler only reports the failed match within Ada.Integer_Text_IO
(with Integer
); if we remove this with
and use
(it isn’t used, after all), things become much more helpful,
1. with Ada.Text_IO; use Ada.Text_IO;
2. -- with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
3. procedure Person_1 is
4. type String is
5. array (Positive range <>) of Character;
6. S: String (1..10);
7. begin
8. Put("Write a name: ");
9. Get(S);
1 4
>>> no candidate interpretations match the actuals:
>>> missing argument for parameter "Item" in call to "Get" declared at a-textio.ads:451
>>> missing argument for parameter "Item" in call to "Get" declared at a-textio.ads:378
>>> expected type "Standard.String"
>>> found type "String" defined at line 4
>>> ==> in call to "Get" at a-textio.ads:454
>>> ==> in call to "Get" at a-textio.ads:381
10. end Person_1;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments