From: karl@grebyn.com (Karl Nyberg)
Subject: Limited types and generic parameters
Date: 23 Feb 89 05:51:18 GMT [thread overview]
Message-ID: <8902230551.AA02866@grebyn.com> (raw)
[Ed - forwarded]
-- Karl --
Mats Weber asks:
>> Consider the following piece of Ada code:
>>
>> generic
>> type T is limited private;
>> package GP is
>>
>> type R is
>> record
>> F : T;
>> end record;
>>
>> end GP;
>>
>> package P is new GP(T => INTEGER);
>>
>> X : P.R := (F => 45); -- *
>> Y : P.R := (F => 77); -- *
>> Are the *-marked assignments correct ? In other words, is P.R a limited
>> type ?
AI-398 answers a similar question for arrays:
... If the component type of an array type is a generic formal type or if
the designated type of an access type is a generic formal type, the
operations declared for the array and access type in the template depend
on the class of the formal type. If the array and access type
declarations do not occur in the generic formal part, then the operations
declared for these types in a generic instance are determined by the type
denoted by the formal parameter in the instance.
This means that if type R in the example were an array type with component
type T, assignments to an object of type R declared in the template would not
be allowed, but assignments to an object declared elsewhere (or in an
instance) would be okay as long as the actual type is not limited.
The reasoning underlying this interpretation for arrays extends to record
types, although these types were not addressed explicitly in the AI. So, in
short, the assignments in the example are considered legal.
Whether compilers support AI-398 is another question. I don't think any tests
on this point exist in the ACVC suite, and even if they did, the test
objectives on this point are (or were) not consistent with AI-398. But since
AI-398 is an approved commentary, compilers ought to support the kind of
assignments indicated in the question.
There are a number of other, rather subtle, issues raised in AI-398 related to
the effects of type derivation, but AI-398 follows the principal that the
appropriate operations are declared in the instance, even if the operations do
not exist in the template.
John B. Goodenough Goodenough@sei.cmu.edu
Software Engineering Institute 412-268-6391
next reply other threads:[~1989-02-23 5:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1989-02-23 5:51 Karl Nyberg [this message]
-- strict thread matches above, loose matches on Subject: below --
1989-02-22 12:27 Limited types and generic parameters Mats Weber
1989-02-22 14:58 ` Fred Hosch
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox