The compiler won’t let me Get a string

Simon Wright

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?

Simon Wright

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android studio won't let me use switch on a string?

From Dev

Dictionary won't let me append a string to its values

From Dev

Why doesn't the compiler let me use a variable in a switch case?

From Dev

Trying to delete string from memory. Won't let me assign to cin

From Dev

Terminal won't let me print pointer to string without newline character at end - C

From Dev

GitHub won't let me push

From Dev

Won't let me open regedit

From Dev

DSUM won't let me give it criteria

From Dev

DiskPart won't let me delete a partition

From Dev

xmlns attribute won't let me parse

From Dev

Excel won't let me paste

From Dev

Git Rebase Won't Let Me Type

From Dev

Why won't it let me pass this list?

From Dev

Ubuntu 16.04 broken kernel packages won't let me install or remove anything with apt-get

From Dev

Ubuntu 16.04 broken kernel packages won't let me install or remove anything with apt-get

From Dev

GCC INLINE ASSEMBLY Won't Let Me Overwrite $esp

From Dev

Laravel 5 eloquent model won't let me update

From Dev

UIAlertView popup won't let me swipe up Control Center

From Java

GitKraken won't let me open my Private Repository on GitLab

From Dev

Cordova Device plugin won't let me access the "device" properties

From Dev

Eclipse sometimes won't let me set libraries for projects

From Dev

Mac Window Won't Let Me Resize to Smaller, possibly constraints?

From Dev

uWSGI won't reload, restart or let me run service

From Dev

Mongoose won't let me insert null value for Number?

From Dev

Xcode won't let me create a new project

From Dev

phpMyAdmin won't let me login - no error shown

From Dev

Laravel won't let me save pagination variable in an array

From Dev

Xcode won't let me upload my app

From Dev

VI won't let me save my vimrc file

Related Related

  1. 1

    Android studio won't let me use switch on a string?

  2. 2

    Dictionary won't let me append a string to its values

  3. 3

    Why doesn't the compiler let me use a variable in a switch case?

  4. 4

    Trying to delete string from memory. Won't let me assign to cin

  5. 5

    Terminal won't let me print pointer to string without newline character at end - C

  6. 6

    GitHub won't let me push

  7. 7

    Won't let me open regedit

  8. 8

    DSUM won't let me give it criteria

  9. 9

    DiskPart won't let me delete a partition

  10. 10

    xmlns attribute won't let me parse

  11. 11

    Excel won't let me paste

  12. 12

    Git Rebase Won't Let Me Type

  13. 13

    Why won't it let me pass this list?

  14. 14

    Ubuntu 16.04 broken kernel packages won't let me install or remove anything with apt-get

  15. 15

    Ubuntu 16.04 broken kernel packages won't let me install or remove anything with apt-get

  16. 16

    GCC INLINE ASSEMBLY Won't Let Me Overwrite $esp

  17. 17

    Laravel 5 eloquent model won't let me update

  18. 18

    UIAlertView popup won't let me swipe up Control Center

  19. 19

    GitKraken won't let me open my Private Repository on GitLab

  20. 20

    Cordova Device plugin won't let me access the "device" properties

  21. 21

    Eclipse sometimes won't let me set libraries for projects

  22. 22

    Mac Window Won't Let Me Resize to Smaller, possibly constraints?

  23. 23

    uWSGI won't reload, restart or let me run service

  24. 24

    Mongoose won't let me insert null value for Number?

  25. 25

    Xcode won't let me create a new project

  26. 26

    phpMyAdmin won't let me login - no error shown

  27. 27

    Laravel won't let me save pagination variable in an array

  28. 28

    Xcode won't let me upload my app

  29. 29

    VI won't let me save my vimrc file

HotTag

Archive