comp.lang.ada
 help / color / mirror / Atom feed
* Overriding procedure as null
@ 2018-03-27 20:26 gautier_niouzes
  2018-03-28  0:08 ` Randy Brukardt
  0 siblings, 1 reply; 2+ messages in thread
From: gautier_niouzes @ 2018-03-27 20:26 UTC (permalink / raw)


Hello,

I've just come across a little "legal" case that was easy to solve practically, but I'm curious about what is "right" Ada.

Consider the following program:

  with Ada.Streams;

  procedure test_overriding is

    type Search_stream is new Ada.Streams.Root_Stream_Type with null record;

    overriding procedure Read
      (Stream : in out Search_stream;
       Item   :    out Ada.Streams.Stream_Element_Array;
       Last   :    out Ada.Streams.Stream_Element_Offset);

    overriding procedure Write
     (Stream : in out Search_stream;
      Item   : in     Ada.Streams.Stream_Element_Array);

    --  Implementation of Read & Write:

    overriding procedure Read
      (Stream : in out Search_stream;
       Item   :    out Ada.Streams.Stream_Element_Array;
       Last   :    out Ada.Streams.Stream_Element_Offset) is null;  --  Unused

    overriding procedure Write
     (Stream : in out Search_stream;
      Item   : in     Ada.Streams.Stream_Element_Array) is
    begin
      null;  --  Something done in real case.
    end;

  begin
    null;
  end;

GNAT (GPL 2017/Win32) compiles seamlessly.
ObjectAda (9.2) issues, for the 2nd "Read":
  test_overriding.adb: Error: line 18 col 24 LRM:8.3(26), Illegal to override declaration in same region, prior declaration is Read at line 7

It looks like OA considers the 2nd occurrence as a specification, not a body - with "is null", it could be both actually.
Who's right ?

To make both compilers happy I just put the "Read(...) is null" at the first place and remove the 2nd one, so it is only a theory/law problem.

More interestingly, if I completely remove the Read procedure, OA still compiles fine and GNAT issues an error  (rightfully I think):
test_overriding.adb:5:10: type must be declared abstract or "read" overridden
test_overriding.adb:5:10: "read" has been inherited from subprogram at a-stream.ads:57

_________________________ 
Gautier's Ada programming 
http://www.openhub.net/accounts/gautier_bd


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

end of thread, other threads:[~2018-03-28  0:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-27 20:26 Overriding procedure as null gautier_niouzes
2018-03-28  0:08 ` Randy Brukardt

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