comp.lang.ada
 help / color / mirror / Atom feed
* implicit array type conversion
@ 1990-07-26 20:56 "Norman H. Cohen"
  0 siblings, 0 replies; 5+ messages in thread
From: "Norman H. Cohen" @ 1990-07-26 20:56 UTC (permalink / 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

^ permalink raw reply	[flat|nested] 5+ messages in thread
[parent not found: <132742@<1990Jul26>]
* implicit array type conversion
@ 1990-07-26 13:27 
  1990-07-26 20:36 ` David Collard
  0 siblings, 1 reply; 5+ messages in thread
From:  @ 1990-07-26 13:27 UTC (permalink / raw)


Why is it that implicit array type conversion does not apply to the
following situation?  I can't find anything in the RM that disallows
this situation for implicit conversion.

The compiler (Verdix Sun 4 Self, version 6.0.2(g)) gives the following
warning for the assignment to B:

warning: RM 3.6.1: bounds check will raise CONSTRAINT_ERROR at runtime

It does raise the exception on execution.

I sorta wanted to get some other views before I flag this to Verdix as a
bug.  Minor flame: Its real easy to miss some statement buried in the RM
which clarifies these kinds of language lawyer issues.

------------------------ cut here ----------------------------------
procedure Strings is

   type STRING (Len : NATURAL) is
      record
         S : Standard.STRING(1..Len);
      end record;

   A : Standard.STRING(7..7);
   B : STRING(1);

begin -- Strings

   A := "X";
   B := (A'length, A);

end Strings;

Terry J. Westley
Arvin/Calspan Advanced Technology Center
P.O. Box 400, Buffalo, NY 14225
acsu.buffalo.edu!planck!hercules!westley

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

end of thread, other threads:[~1990-07-27 17:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1990-07-26 20:56 implicit array type conversion "Norman H. Cohen"
     [not found] <132742@<1990Jul26>
1990-07-27 16:01 ` 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

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