comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Type extension and discriminants
Date: Fri, 10 Oct 2014 17:34:52 -0500
Date: 2014-10-10T17:34:52-05:00	[thread overview]
Message-ID: <m19muc$551$1@loke.gir.dk> (raw)
In-Reply-To: 8d6fe2a6-a8fa-441f-8b35-fc5a744359fb@googlegroups.com

It would have helped a bit had you given an example. I'm presuming you're 
talking about something like:

package P1 is
    type T (<>) is tagged private;
...
end P1;

with P1;
package P2 is
    type NT (???) is new P1.T with private;
....
end P2;

and you want to know how NT is declared.

If you had:
   type NT (D : E) is new P1.T with private;
RM 3.7(12-13) would be violated, so this is illegal.

If you had:
   type NT (D : E) is new P1.T (D) with private;

At least RM 3.7(15) would be violated (and there are probably more), so this 
is also illegal.

As you noted, 3.7(26) says that
    type NT is new P1.T with private;
has unknown discriminants, so this declaration is legal. As you note, you'd 
need an extension aggregate to initialize that. I think that should be legal 
as well (I can't think of a reason off hand that it shouldn't be).

I'd rather have the unknown discriminants explicit, as in:
    type NT(<>) is new P1.T with private;
This would need the same kind of extension aggregate.

My guess is that you've hit some sort of compiler bug (this is a little used 
area in my experience), but it's hard to tell without seeing a complete 
example.

                                          Randy.


<sbelmont700@gmail.com> wrote in message 
news:8d6fe2a6-a8fa-441f-8b35-fc5a744359fb@googlegroups.com...
Hi,

GNAT is giving me odd errors, strange crashes, and dubious successes, so to 
be safe I will ask the experts: what are the rules behind extending types 
with discriminants (specifically unknown) from non-child packages?

Consider T1, declared with unknown discriminants in the public part of 
package A, and then T2 which extends T1 in package B.  T2 can't see which 
(if any) discriminants T1 actually has, so it stands to reason T2 must be 
also declared with unknown discriminants (perhaps implicitly, given 3.7~26: 
"if derived, such a type has the same sort of discriminants (known, unknown, 
or none) as its parent (or ancestor) type").  Consequently, any constructor 
function that builds a T2 would need to use an extension aggregate, 
specifying one of T1's constructor functions to build the unknown parts. 
This is what I would assume, but GNAT crashes when trying to compile such 
constructs.

However, if T2 tries to add discriminants, it would fall into the trap of 
needing to define T1's discriminants, which it could not since it has no 
idea if they exist or not.  Seemingly the best it could do is create 
discriminants for whatever arguments T1's constructor function would need, 
and use those as arguments in the type declaration?  As in:

type T2 (x : y, a : b) is new T1 (A.T1_Ctor(x)) with ...

Is this generally correct, or are there other esoteric problems that 
prevents these sort of constructs?

-sb 



  reply	other threads:[~2014-10-10 22:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-10 20:55 Type extension and discriminants sbelmont700
2014-10-10 22:34 ` Randy Brukardt [this message]
2014-10-11 17:45   ` sbelmont700
2014-10-11 18:44     ` Simon Wright
2014-10-11 18:52     ` Dmitry A. Kazakov
2014-10-11 21:09       ` sbelmont700
2014-10-12  6:51         ` Dmitry A. Kazakov
2014-10-12 16:27     ` AdaMagica
replies disabled

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