comp.lang.ada
 help / color / mirror / Atom feed
From: ytomino <aghia05@gmail.com>
Subject: Class wide preconditions: error in GNAT implementation?
Date: Thu, 14 Feb 2013 19:55:32 -0800 (PST)
Date: 2013-02-14T19:55:32-08:00	[thread overview]
Message-ID: <e155e2d6-ba1f-4fc0-a6e3-dafde002670b@googlegroups.com> (raw)

Hello.
I read https://groups.google.com/d/topic/comp.lang.ada/03cKrGghF2Y/discussion and recall a related question.

See below example:

package preconds is
   package Tools is
      function Write_In_Expr (S : String) return Boolean; -- Put_Line (S) and return True
   end Tools;
   package As is
      type A is tagged null record;
      procedure foo (Object : A) -- empty body
         with Pre'Class => Tools.Write_In_Expr ("A, in!"),
              Post'Class => Tools.Write_In_Expr ("A, out!");
   end As;
   package Bs is
      type B is new As.A with null record;
      overriding procedure foo (Object : B) -- empty body
         with Pre'Class  => Tools.Write_In_Expr ("B, in!"), -- [*]
              Post'Class => Tools.Write_In_Expr ("B, out!");
   end Bs;
end preconds;

with preconds; use preconds;
procedure precondmain is
   x : access As.A'Class := new Bs.B;
begin
   As.foo (x.all); -- dispatching call as A'Class
end precondmain;

% gnatmake -gnat2012 -gnata precondmain.adb
% ./precondmain
B, in!
B, out!
A, out!

And change [*] to Pre'Class => Tools.Write_In_Expr ("B, in!") and False,

% gnatmake -gnat2012 -gnata precondmain.adb
% ./precondmain                            
B, in!
A, in!
B, out!
A, out!

It seems that the preconditions were evaluated as pragma Assert (B'Pre'Class and then A'Pre'Class);

By the way, AARM 6.1.1 38.a/3-b/3 says

> Ramification: For a dispatching call, we are talking about the Pre'Class(es) that apply to the subprogram that the dispatching call is resolving to, not the Pre'Class(es) for the subprogram that is ultimately dispatched to. The class-wide precondition of the resolved call is necessarily the same or stronger than that of the invoked call. For a statically bound call, these are the same; for an access-to-subprogram, (which has no class-wide preconditions of its own), we check the class-wide preconditions of the invoked routine. 

>Implementation Note: These rules imply that logically, class-wide preconditions of routines must be checked at the point of call (other than for access-to-subprogram calls, which must be checked in the body, probably using a wrapper). Specific preconditions that might be called with a dispatching call or via an access-to-subprogram value must be checked inside of the subprogram body. In contrast, the postcondition checks always need to be checked inside the body of the routine. Of course, an implementation can evaluate all of these at the point of call for statically bound calls if the implementation uses wrappers for dispatching bodies and for 'Access values.

I think(hope), this two lines mean only A'Pre'Class should be evaluated in this case.

B'Pre'Class should not be evaluated in this case. Isn't it?

P.S. dmd (D language compiler) had same error. Its discussion may help for reference.
http://d.puremagic.com/issues/show_bug.cgi?id=6857




             reply	other threads:[~2013-02-15  3:55 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-15  3:55 ytomino [this message]
2013-02-15 10:15 ` Class wide preconditions: error in GNAT implementation? Georg Bauhaus
2013-02-15 13:16   ` ytomino
2013-02-16  1:01 ` Randy Brukardt
2013-02-16  2:50   ` ytomino
2013-02-16  9:28     ` Dmitry A. Kazakov
2013-02-16 13:13       ` ytomino
2013-02-16 16:35         ` Dmitry A. Kazakov
2013-02-16 19:55           ` ytomino
2013-02-16 20:34             ` ytomino
2013-02-18  8:30             ` Dmitry A. Kazakov
2013-02-18  9:17               ` Simon Wright
2013-02-18 14:25                 ` Dmitry A. Kazakov
2013-02-18 18:04                   ` Simon Wright
2013-02-18 19:27                     ` Dmitry A. Kazakov
2013-02-18 20:42                       ` Simon Wright
2013-02-19  9:07                         ` Dmitry A. Kazakov
2013-02-18 19:02               ` ytomino
2013-02-18 19:44                 ` Dmitry A. Kazakov
2013-02-16 15:16       ` Georg Bauhaus
2013-02-16 20:23   ` Simon Wright
2013-02-17 15:12     ` ytomino
2013-02-18 17:49       ` Simon Wright
2013-02-18 18:45         ` ytomino
replies disabled

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