From: NCOHEN@IBM.COM ("Norman H. Cohen")
Subject: implicit array type conversion
Date: 26 Jul 90 20:56:19 GMT [thread overview]
Message-ID: <9007262057.AA05469@ajpo.sei.cmu.edu> (raw)
Given the declarations
type My_String (Len : Natural) is
record
S : String (1..Len);
end record;
A : String(7..7);
B : My_String(1);
Terry Westley questions the raising of Constraint_Error by the
following statement:
B := (A'Length, A);
(I have changed the name of Westley's record type to avoid confusion.)
The exception is raised not by the assignment-statement check that the
value of the righthand side belongs to the subtype of the lefthand side,
but by the evaluation of the aggregate. (The same thing would happen
if the assignment to B were replaced by
C := (A'Length, A) = My_String'(1, "X");
where C is of type Boolean.)
RM 4.3.1(3) states:
For the evaluation of a record aggregate, the expressions given in the
component associations are evaluated in some order that is not
defined by the language.... A check is made that the value of each
subcomponent of the aggregate belongs to the subtype of this
subcomponent. The exception CONSTRAINT_ERROR is raised if this check
fails.
In this case, the value of A belongs to subtype String(7 .. 7) (because
that's how A is declared) but the subtype of the second component of
the aggregate (deduced from the type declaration for My_String and the
discriminant value given by the first component in the aggregate) is
String(1 .. 1).
There's nothing in the RM to suggest that an implicit subtype conversion
takes place here. Such conversions are mentioned only in 5.2(3) and
5.2.1(1), and only for assignment statements in which the lefthand side
is a variable of an array type.
The only problem with the compiler is that its warning message ought to
have cited 4.3.1(3) rather than 3.6.1.
Norman H. Cohen
next reply other threads:[~1990-07-26 20:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1990-07-26 20:56 "Norman H. Cohen" [this message]
[not found] <132742@<1990Jul26>
1990-07-27 16:01 ` implicit array type conversion stt
-- strict thread matches above, loose matches on Subject: below --
1990-07-26 13:27
1990-07-26 20:36 ` David Collard
1990-07-27 17:13 ` Michael Feldman
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox