comp.lang.ada
 help / color / mirror / Atom feed
* Abstract Completion Question
@ 1999-03-04  0:00 Nick Roberts
  1999-03-05  0:00 ` Tucker Taft
  1999-03-05  0:00 ` Robert A Duff
  0 siblings, 2 replies; 5+ messages in thread
From: Nick Roberts @ 1999-03-04  0:00 UTC (permalink / raw)


-- Consider the following code:

with Ada.Text_IO; use Ada.Text_IO;

procedure Test_1 is

   package P1 is
      type T1 is abstract tagged null record;
      procedure A (X: in T1) is abstract;
   end;

   type T2 is new P1.T1 with
      record
         Data: String(1..10) := "***DATA***";
      end record;

   procedure A (X: in T2) is
   begin
      Put_Line(X.Data);
   end;

   type T1CA is access all P1.T1'Class;

   Y: aliased T2;
   Z: T1CA := Y'Access;

begin

   P1.A(Z.all); -- dispatching call

end;

-- The operation "A" of type "T2" is overridden, so fulfilling the promise
-- of type "T1" (as far as Ada is concerned).  This program compiles
-- and runs (GNAT 3.11p Win32), but nevertheless "A" is not a primitive
-- operation of "T2" (because it is not declared in a package spec), so
-- "A" cannot be dispatched to.  Upon executing this program under
-- GNAT, Constraint_Error is raised.  This behaviour could be a
-- 'surprise' for users (a nasty one).  Comments?

-------------------------------------
-- Nick Roberts
-------------------------------------









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

* Re: Abstract Completion Question
  1999-03-04  0:00 Abstract Completion Question Nick Roberts
@ 1999-03-05  0:00 ` Tucker Taft
  1999-03-06  0:00   ` Nick Roberts
  1999-03-05  0:00 ` Robert A Duff
  1 sibling, 1 reply; 5+ messages in thread
From: Tucker Taft @ 1999-03-05  0:00 UTC (permalink / raw)


Nick Roberts wrote:
> 
> -- Consider the following code:
> 
> with Ada.Text_IO; use Ada.Text_IO;
> 
> procedure Test_1 is
> 
>    package P1 is
>       type T1 is abstract tagged null record;
>       procedure A (X: in T1) is abstract;
>    end;
> 
>    type T2 is new P1.T1 with
>       record
>          Data: String(1..10) := "***DATA***";
>       end record;
> 
>    procedure A (X: in T2) is
>    begin
>       Put_Line(X.Data);
>    end;
> 
>    type T1CA is access all P1.T1'Class;
> 
>    Y: aliased T2;
>    Z: T1CA := Y'Access;
> 
> begin
> 
>    P1.A(Z.all); -- dispatching call
> 
> end;
> 
> -- The operation "A" of type "T2" is overridden, so fulfilling the promise
> -- of type "T1" (as far as Ada is concerned).  This program compiles
> -- and runs (GNAT 3.11p Win32), but nevertheless "A" is not a primitive
> -- operation of "T2" (because it is not declared in a package spec), so
> -- "A" cannot be dispatched to. 

A *is* a primitive operation of T2, because it overrides an
inherited subprogram (RM95 3.2.3(7)).

> ... Upon executing this program under
> -- GNAT, Constraint_Error is raised.  This behaviour could be a
> -- 'surprise' for users (a nasty one).  Comments?

Perhaps you have run into a GNAT bug, or perhaps the Constraint_Error
is due to some other error in your program.  From a language
point of view, the dispatching call should be going to the
body of A containing the Put_Line.
 
> -------------------------------------
> -- Nick Roberts
> -------------------------------------

-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




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

* Re: Abstract Completion Question
  1999-03-04  0:00 Abstract Completion Question Nick Roberts
  1999-03-05  0:00 ` Tucker Taft
@ 1999-03-05  0:00 ` Robert A Duff
  1999-03-06  0:00   ` Nick Roberts
  1 sibling, 1 reply; 5+ messages in thread
From: Robert A Duff @ 1999-03-05  0:00 UTC (permalink / raw)


"Nick Roberts" <Nick.Roberts@dial.pipex.com> writes:

> -- Consider the following code:
> 
> with Ada.Text_IO; use Ada.Text_IO;
> 
> procedure Test_1 is
> 
>    package P1 is
>       type T1 is abstract tagged null record;
>       procedure A (X: in T1) is abstract;
>    end;
> 
>    type T2 is new P1.T1 with
>       record
>          Data: String(1..10) := "***DATA***";
>       end record;
> 
>    procedure A (X: in T2) is
>    begin
>       Put_Line(X.Data);
>    end;
> 
>    type T1CA is access all P1.T1'Class;
> 
>    Y: aliased T2;
>    Z: T1CA := Y'Access;
> 
> begin
> 
>    P1.A(Z.all); -- dispatching call
> 
> end;
> 
> -- The operation "A" of type "T2" is overridden, so fulfilling the promise
> -- of type "T1" (as far as Ada is concerned).  This program compiles
> -- and runs (GNAT 3.11p Win32), but nevertheless "A" is not a primitive
> -- operation of "T2" (because it is not declared in a package spec), so
> -- "A" cannot be dispatched to.  Upon executing this program under
> -- GNAT, Constraint_Error is raised.  This behaviour could be a
> -- 'surprise' for users (a nasty one).  Comments?

Procedure A of T2 *is* primitive, because it overrides.  See 3.2.3(7).
The call should dispatch to this procedure A, as you would expect.

It's not clear to me why it's raising C_E -- perhaps a compiler bug, or
perhaps something I'm missing in the above code.

A language design goal was, "no dangling dispatching".  If you can
dispatch (legally at compile time), then there must be a procedure there
(at run time) to dispatch to.  If you find a violation of that
principle, I want to hear about it!

- Bob
-- 
Change robert to bob to get my real email address.  Sorry.




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

* Re: Abstract Completion Question
  1999-03-05  0:00 ` Tucker Taft
@ 1999-03-06  0:00   ` Nick Roberts
  0 siblings, 0 replies; 5+ messages in thread
From: Nick Roberts @ 1999-03-06  0:00 UTC (permalink / raw)


Well, the declaration of A in the example was a body which serves as a
declaration, i.e. it is not a completion of a prior declaration. The
addition of such a declaration causes GNAT to produce a program which runs
normally, so I suspect a GNAT bug (and I have submitted a report to
"report@gnat.com").  Assuming it is a bug, the workaround is presumably
extremely simple: always include a prior declaration in these situations.

-------------------------------------
Nick Roberts
-------------------------------------

Tucker Taft wrote in message <36DFF8BC.80853D3C@averstar.com>...
[...]
|Perhaps you have run into a GNAT bug, or perhaps the Constraint_Error
|is due to some other error in your program.  From a language
|point of view, the dispatching call should be going to the
|body of A containing the Put_Line.
[...]
|-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
|Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
|AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA








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

* Re: Abstract Completion Question
  1999-03-05  0:00 ` Robert A Duff
@ 1999-03-06  0:00   ` Nick Roberts
  0 siblings, 0 replies; 5+ messages in thread
From: Nick Roberts @ 1999-03-06  0:00 UTC (permalink / raw)


Robert A Duff wrote in message ...
[...]
|It's not clear to me why it's raising C_E -- perhaps a compiler bug, or
|perhaps something I'm missing in the above code.

[...]

I think it is a compiler bug (I have submitted a GNAT bug report).

-------------------------------------
Nick Roberts
-------------------------------------









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

end of thread, other threads:[~1999-03-06  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-04  0:00 Abstract Completion Question Nick Roberts
1999-03-05  0:00 ` Tucker Taft
1999-03-06  0:00   ` Nick Roberts
1999-03-05  0:00 ` Robert A Duff
1999-03-06  0:00   ` Nick Roberts

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