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: Fri, 24 Mar 2023 10:41:20 +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: Fri, 24 Mar 2023 09:41:10 -0000 (UTC) Injection-Info: dont-email.me; posting-host="31b98b1fe80e6ee8ff82eb92b5260268"; logging-data="1700073"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/WXlXkA+utur8cylyywTHI" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Cancel-Lock: sha1:QIjGgYLy3lINWcN6/fQ0oxRyD9E= In-Reply-To: Content-Language: en-US, fr Xref: feeder.eternal-september.org comp.lang.ada:65018 List-Id: Le 23/03/2023 à 19:55, Niklas Holsti a écrit : > >> 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! > > > This error is understandable and valid, because now P.all is PF2.all > which is an allocated object and therefore constrained by its initial > value with K = F2. > > But why should the same apply when P designates X, which is > unconstrained? Is it just an optimization (in the RM) so that a > general access value does not have to carry around a flag showing > whether its designated object is constrained or unconstrained? I didn't dig in the RM in all details, but I think this comes from the fact that being constrained (always) is a property of the pointer (more precisely, its subtype), not of the pointed-at object. -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX https://www.adalog.fr https://www.adacontrol.fr