comp.lang.ada
 help / color / mirror / Atom feed
From: sbelmont700@gmail.com
Subject: Type extension and discriminants
Date: Fri, 10 Oct 2014 13:55:45 -0700 (PDT)
Date: 2014-10-10T13:55:45-07:00	[thread overview]
Message-ID: <8d6fe2a6-a8fa-441f-8b35-fc5a744359fb@googlegroups.com> (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


             reply	other threads:[~2014-10-10 20:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-10 20:55 sbelmont700 [this message]
2014-10-10 22:34 ` Type extension and discriminants 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
replies disabled

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