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=-3.2 required=3.0 tests=BAYES_00,NICE_REPLY_A, 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: "J-P. Rosen" Newsgroups: comp.lang.ada Subject: Re: Assignment access type with discriminants Date: Thu, 23 Mar 2023 18:04:36 +0100 Organization: Adalog Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Thu, 23 Mar 2023 17:04:29 -0000 (UTC) Injection-Info: dont-email.me; posting-host="3a2cff23be8de86e9fe5e1bc7e53e790"; logging-data="1304031"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18QEz35KcVdo7tZ7fdHNGYs" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Cancel-Lock: sha1:4DgjWTN8wgG7VtyoAI8CNRR0jwY= Content-Language: en-US, fr In-Reply-To: Xref: feeder.eternal-september.org comp.lang.ada:65013 List-Id: Le 22/03/2023 à 10:19, Dmitry A. Kazakov a écrit : > 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! > (...) > Is this a compiler bug or intentional language design? Any language > lawyers? > An access value is always constrained by its initial value; this is necessary because of constrained access subtypes. Here is a slightly modified version of your example: 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; type Foo_Ptr2 is access Foo; X : aliased Foo; P : Foo_Ptr := X'Access; PF2: Foo_PTR2 (F2); begin X := (F2, 1.0); -- OK PF2 := new Foo (F2); P := PF2.all'Access; P.all := (F1, 3); -- Error! end Test; Without this rule, PF2.all would now designate a value whose discriminant is F1! -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX https://www.adalog.fr https://www.adacontrol.fr