From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ames!rex!samsung!usc!sdd.hp.com!decwrl!ucbvax!IBM.COM!NCOHEN From: NCOHEN@IBM.COM ("Norman H. Cohen") Newsgroups: comp.lang.ada Subject: implicit array type conversion Message-ID: <9007262057.AA05469@ajpo.sei.cmu.edu> Date: 26 Jul 90 20:56:19 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet List-Id: 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