comp.lang.ada
 help / color / mirror / Atom feed
* Basic issue with dotted notation and tagged types
@ 2012-10-21 22:55 Yannick Duchêne (Hibou57)
  2012-10-22  7:46 ` J-P. Rosen
  2012-10-22 10:41 ` AdaMagica
  0 siblings, 2 replies; 12+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2012-10-21 22:55 UTC (permalink / raw)


I can't remember if this was already discussed here, somewhere in a  
rationale or an RM comment, here is something I really don't like, with a  
field (or member) of a tagged type and a function, both of the same name;  
a very basic case:


     with Ada.Text_IO;

     procedure Test2 is

        package IO renames Ada.Text_IO;

        -- type T is tagged;
        -- function F (E : T'Class) return Character;

        type T
           is tagged record
              F : Character := 'A';
           end record;

        function F
          (E : T'Class)
           return Character
           is ('B');

        E : T;
        C : Character := E.F; -- The function or the field?
     begin
        IO.Put (C);
     end;


Will this display `A` or `B`? Actually, the program compiled with GNAT  
4.6, displays `A`. It displays the same even when the two commented lines  
are commented‑out and thus the function `F` is declared before the field  
`F`. I can't remember if the RM have special wordings about it, but I feel  
this does not honour the principle of least surprise. May be this should  
be disallowed, to access any one of the two, when both are together  
visible from a scope?


-- 
“Syntactic sugar causes cancer of the semi-colons.” [1]
“Structured Programming supports the law of the excluded muddle.” [1]
[1]: Epigrams on Programming — Alan J. — P. Yale University



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2012-10-29  2:40 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-21 22:55 Basic issue with dotted notation and tagged types Yannick Duchêne (Hibou57)
2012-10-22  7:46 ` J-P. Rosen
2012-10-22  8:02   ` Dmitry A. Kazakov
2012-10-22 13:46     ` Yannick Duchêne (Hibou57)
2012-10-22 10:52   ` Marius Amado-Alves
2012-10-22 11:18     ` Georg Bauhaus
2012-10-22 11:37       ` Marius Amado-Alves
2012-10-22 14:11       ` Yannick Duchêne (Hibou57)
2012-10-22 11:45     ` Niklas Holsti
2012-10-22 14:17       ` Maciej Sobczak
2012-10-22 13:50     ` Yannick Duchêne (Hibou57)
2012-10-22 10:41 ` AdaMagica

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox