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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.90.202 with SMTP id by10mr19096724pab.39.1439212480410; Mon, 10 Aug 2015 06:14:40 -0700 (PDT) X-Received: by 10.140.105.102 with SMTP id b93mr187007qgf.26.1439212480366; Mon, 10 Aug 2015 06:14:40 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!pg9no8366384igb.0!news-out.google.com!78ni9102qge.1!nntp.google.com!69no4803897qgl.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 10 Aug 2015 06:14:40 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=193.163.1.105; posting-account=Srm5lQoAAAAEMX9rv2ilEKR6FDPapmSq NNTP-Posting-Host: 193.163.1.105 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Unexpected discriminant check failure involving access types From: Mark Lorenzen Injection-Date: Mon, 10 Aug 2015 13:14:40 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:27403 Date: 2015-08-10T06:14:40-07:00 List-Id: On Monday, August 10, 2015 at 2:38:23 PM UTC+2, Markus Sch=F6pflin wrote: > Given the following piece of code: >=20 > ---%<--- > 1 procedure TEST > 2 is > 3 type T is (T1, T2); > 4 > 5 type RECORD_T (X : T :=3D T1) is record > 6 null; > 7 end record; > 8 > 9 type PTR_T is access RECORD_T; > 10 > 11 FOO : RECORD_T; > 12 FOO_PTR : constant PTR_T :=3D new RECORD_T; > 13 > 14 FOO1 : constant RECORD_T :=3D (X =3D> T1); > 15 FOO2 : constant RECORD_T :=3D (X =3D> T2); > 16 begin > 17 FOO :=3D FOO1; > 18 FOO :=3D FOO2; > 19 > 20 FOO_PTR.all :=3D FOO1; > 21 FOO_PTR.all :=3D FOO2; > 22 end; > --->%--- >=20 > When compiled and executed, I get: >=20 > > ./test >=20 > raised CONSTRAINT_ERROR : test.adb:21 discriminant check failed >=20 > Can anyone please explain me why I get a discriminant check error when us= ing=20 > access types? I would have expected it to work the same as for the non-ac= cess=20 > case. >=20 > TIA, Markus Look at line 12. FOO_PTR is a constant object of an access type. The consta= nt object is initialized to point to a discriminated record with discrimina= nt T1, since this is the default discriminant of objects of type RECORD_T. = In line 21 it goes horribly wrong and you try to change the object pointed = to, to a record with discriminant T2. What problem are you trying to solve? Is the above code just a simple repro= ducer or is it a snippet from real code? Regards, Mark L