comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Bad influence of private part on what subprograms can be defined
Date: Mon, 9 Oct 2017 09:25:52 +0200
Date: 2017-10-09T09:25:52+02:00	[thread overview]
Message-ID: <orf8a1$oc2$1@gioia.aioe.org> (raw)
In-Reply-To: orea6h$1fva$1@gioia.aioe.org

On 09/10/2017 00:52, Victor Porton wrote:
> The following does not compile:
> 
> $ gnatmake -gnat2012 test
> gcc-7 -c -gnat2012 test.adb
> test.adb:18:20: subprogram "X" overrides inherited operation at line 21
> gnatmake: "test.adb" compilation error
> 
> 
> -- test.adb
> procedure Test is
> 
>    package A is
>      type A_Type is tagged null record;
>      not overriding procedure X(Object: A_Type);
>    end;
> 
>    package body A is
>      procedure X(Object: A_Type) is
>      begin
>        null;
>      end;
>    end;
> 
>    package B is
>      type B_Type is tagged private;
>      not overriding procedure X(Object: B_Type);
>    private
> --     type B_Type is tagged null record;
>      type B_Type is new A.A_Type with null record;
>    end;
> 
>    package body B is
>      procedure X(Object: B_Type) is
>      begin
>        null;
>      end;
>    end;
> 
> begin
>    null;
> end;
> 
> 
> So private part badly influences what can and what can and what cannot be
> done in the public part. Private must be private!

Yes, but it does not apply here. B has full visibility on B_Type. There 
is nothing private about how B is going to implement B_Type. An 
implementation that inherits from A_Type is incorrect when X is not from 
the class (not overriding) and the compiler dully states that.

When you qualify X as type-specific (not overriding) you wanted exactly 
that sort of check.

Note that the situation would be different if A were a private package. 
Then of course the public part of B should be free to declare X 
independently on private A_Type. Then there would be a problem with 
clients that could see both A and privates of B. But AFAIK this kind of 
scenario is impossible to construct.

> Really bad!

I don't see anything bad here. There are bad cases, e.g. private 
interfaces and others, but this one is OK to me.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2017-10-09  7:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-08 22:52 Bad influence of private part on what subprograms can be defined Victor Porton
2017-10-09  7:25 ` Dmitry A. Kazakov [this message]
2017-10-09  9:25   ` AdaMagica
2017-10-09 10:19     ` AdaMagica
2017-10-09 22:02 ` Randy Brukardt
replies disabled

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