comp.lang.ada
 help / color / mirror / Atom feed
* GNAT doing macro‑expansion for generics? (Pre/Post conditions)
@ 2012-10-18 23:44 Yannick Duchêne (Hibou57)
  2012-10-19  0:08 ` GNAT doing macro‑expansion? " Yannick Duchêne (Hibou57)
  2012-10-24 16:40 ` Yannick Duchêne (Hibou57)
  0 siblings, 2 replies; 10+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2012-10-18 23:44 UTC (permalink / raw)


Is this GNAT doing macro‑expansion for generics, or me missing some trick  
of Ada 2012?

Small snippet first, then comments below (not Ada comments).


     -- g.ads

     package G is

        pragma Pure;

        type E
           is (E1, E2, E3);

        type I_Type
           is interface;

        function F
          (I : I_Type)
           return E
           is abstract;

        procedure P
          (I : I_Type)
           is abstract
           with Pre'Class => F (I) = E1;

     end;


     -- m.adb

     with G;

     procedure M is

        type I_Type
           is new G.I_Type
           with null record;

        overriding function F (I : I_Type) return G.E;
        overriding procedure P (I : I_Type);

        -- subtype E is G.E;
        -- E1 : constant E := G.E1;
        -- use type E;

        function F (I : I_Type) return G.E
           is (G.E1);

        procedure P (I : I_Type) is
           begin null; end;

     begin
        null;
     end;


GNAT can compile package `G`, but while compiling `M`, complains `E1`  
(from the precondition of `P` in `G`) is not visible in `M`. Un‑commenting  
the three initially commented lines solves the issue, but still leave me  
with a feeling, things are going here as if a kind of macro‑expansion was  
applying. The precondition should be compiled in the context of its  
definition, isn't it?

Other funny stuff: in the precondition of P, substitute `P (I)` to `F  
(I)`. GNAT will compile `G` without a complain, and will only figure  
something is wrong while compiling `M`. Is this GNAT's fault, or mine  
missing something?

Note: both occur using FSF GNAT 4.6


-- 
“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] 10+ messages in thread

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

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-18 23:44 GNAT doing macro‑expansion for generics? (Pre/Post conditions) Yannick Duchêne (Hibou57)
2012-10-19  0:08 ` GNAT doing macro‑expansion? " Yannick Duchêne (Hibou57)
2012-10-24 16:40 ` Yannick Duchêne (Hibou57)
2012-10-24 16:45   ` Yannick Duchêne (Hibou57)
2012-10-24 17:20     ` Yannick Duchêne (Hibou57)
2012-10-24 18:16       ` GNAT doing macro-expansion? " Anh Vo
2012-10-24 18:43         ` Yannick Duchêne (Hibou57)
2012-10-24 18:53           ` Simon Wright
2012-10-24 19:02             ` Yannick Duchêne (Hibou57)
2012-10-24 21:43               ` Simon Wright

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