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.7 required=3.0 tests=BAYES_00,NICE_REPLY_A, REPLYTO_WITHOUT_TO_CC,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 Path: eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: "G.B." Newsgroups: comp.lang.ada Subject: Re: Assignment access type with discriminants Date: Wed, 22 Mar 2023 15:10:44 +0100 Organization: A noiseless patient Spider Message-ID: References: Reply-To: nonlegitur@notmyhomepage.de MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 22 Mar 2023 14:10:44 -0000 (UTC) Injection-Info: dont-email.me; posting-host="7465433de0dc0165a3f058124deedfb9"; logging-data="702008"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+QxNbxeavoBl3XsuT1C21Ix2Enk8pEGLk=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Cancel-Lock: sha1:d89ZoZiqHJDpM0Bg2CxybsF05sY= Content-Language: en-US In-Reply-To: Xref: feeder.eternal-september.org comp.lang.ada:65010 List-Id: On 22.03.23 10:19, Dmitry A. Kazakov wrote: > 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; Some experiments point at the general access type. type Foo_Ptr is access Foo; -- sans `all` X : Foo; P : Foo_Ptr := new Foo; type Foo1 is new Foo_Ptr (K => F1); begin X := (F2, 1.0); -- OK P.all := (F1, 3); -- _no_ Error! Foo1 (P).all := (F1, 3); end Test; (Doesn't rejection for general access types seem reasonable if assignment would otherwise require adjusting the storage layout of a variable, including all access paths to components? Just guessing.)