comp.lang.ada
 help / color / mirror / Atom feed
From: "Alejandro R. Mosteo" <alejandro@mosteo.com>
Subject: Re: Generic private type declaration
Date: Mon, 28 Nov 2016 15:54:35 +0100
Date: 2016-11-28T15:54:35+01:00	[thread overview]
Message-ID: <o1hgcu$ugg$1@dont-email.me> (raw)
In-Reply-To: <o1a2o2$1f9o$1@gioia.aioe.org>

On 25/11/16 20:17, Dmitry A. Kazakov wrote:
> On 2016-11-25 18:36, Alejandro R. Mosteo wrote:
>
>> I need some eyes on this error because I'm missing something basic. When
>> compiling this code:
>>
>> procedure B001_Tagged is
>>
>>    generic
>>       type X is private;
>>    package Untagged is
>>
>>       type Y is new X;
>>
>>    end Untagged;
>>
>>    package Ok is new Untagged (Integer);
>>
>>    type Void is tagged null record;
>>
>>    package Err is new Untagged (Void); --  Error here
>>
>> begin
>>    null;
>> end B001_Tagged;
>>
>> I get in both gnat 4.9.3 and gpl2016 the following error:
>>
>> b001_tagged.adb:15:04: instantiation error at line 7
>> b001_tagged.adb:15:04: type derived from tagged type must have extension
>> gnatmake: "b001_tagged.adb" compilation error
>>
>> I would expect that the view inside the generic package is untagged and
>> so the type renaming in line 7 should be correct? Or I'm floundering
>> with the generic parameter declaration?
>
> Yes, generics leak privacy and don't respect any contracts much.
> Sometimes an actual tagged type matches formal private type and
> sometimes it does not. Visibility rules are broken with respect to
> tagged types even without generics (see earlier discussions about
> private overriding).

I'm still trying to come to terms with the RM and the other answers 
posted, but I must say that if GNAT is correct in this case, it makes me 
uneasily feel in C++ templating territory.

Alex.

> Ada lawyers will surely tell you that it is OK because it cannot be
> fixed. In some sense generics are indeed beyond any hope being weakly
> typed, but still most outrageous examples could be fixed nevertheless.
> And visibility rules can be fixed for sure.


  reply	other threads:[~2016-11-28 14:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-25 17:36 Generic private type declaration Alejandro R. Mosteo
2016-11-25 19:17 ` Dmitry A. Kazakov
2016-11-28 14:54   ` Alejandro R. Mosteo [this message]
2016-11-25 19:18 ` AdaMagica
2016-11-28 14:57   ` Alejandro R. Mosteo
2016-11-25 19:38 ` G.B.
2016-11-26  8:45 ` Jacob Sparre Andersen
2016-11-26 19:18   ` Tero Koskinen
2016-11-28 15:05     ` Alejandro R. Mosteo
2016-11-28 21:32       ` Randy Brukardt
2016-11-29 11:12         ` Alejandro R. Mosteo
2016-11-29 11:42         ` Dmitry A. Kazakov
2016-11-29 23:48           ` Randy Brukardt
2016-11-28 23:25 ` Robert Eachus
replies disabled

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