From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Assignment access type with discriminants Date: Wed, 22 Mar 2023 10:19:28 +0100 Organization: A noiseless patient Spider Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 22 Mar 2023 09:19:26 -0000 (UTC) Injection-Info: dont-email.me; posting-host="c7c1c8477de057a13cc37bfa1f0b0dc2"; logging-data="608062"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+jRSPnQIRypuzXFDDTeIcp2M32Yg8CThY=" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Cancel-Lock: sha1:r7xEKsRHIW5CQPQEnSEVRdreN78= Content-Language: en-US Xref: feeder.eternal-september.org comp.lang.ada:65008 List-Id: I stumbled on a curious fact. The value of an object with a discriminant can be changed to a value with a different discriminant if the type's discriminants are defaulted. Right? Wrong! Not through an access type! procedure Test is type F is (F1, F2, F3); type Foo (K : F := F1) is record case K is when F1 => X1 : Integer; when F2 => X2 : Float; when F3 => X3 : String (1..2); end case; end record; type Foo_Ptr is access all Foo; X : aliased Foo; P : Foo_Ptr := X'Access; begin X := (F2, 1.0); -- OK P.all := (F1, 3); -- Error! end Test; Is this a compiler bug or intentional language design? Any language lawyers? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de