comp.lang.ada
 help / color / mirror / Atom feed
From: "Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr>
Subject: GNAT doing macro‑expansion for generics? (Pre/Post conditions)
Date: Fri, 19 Oct 2012 01:44:29 +0200
Date: 2012-10-19T01:44:29+02:00	[thread overview]
Message-ID: <op.wmeewfh4ule2fv@cardamome> (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



             reply	other threads:[~2012-10-18 23:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-18 23:44 Yannick Duchêne (Hibou57) [this message]
2012-10-19  0:08 ` GNAT doing macro‑expansion? (Pre/Post conditions) 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
replies disabled

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