comp.lang.ada
 help / color / mirror / Atom feed
* Type extension and discriminants
@ 2014-10-10 20:55 sbelmont700
  2014-10-10 22:34 ` Randy Brukardt
  0 siblings, 1 reply; 8+ messages in thread
From: sbelmont700 @ 2014-10-10 20:55 UTC (permalink / raw)


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


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

end of thread, other threads:[~2014-10-12 16:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-10 20:55 Type extension and discriminants sbelmont700
2014-10-10 22:34 ` Randy Brukardt
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

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