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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e408bb0b4469b67c X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.megapath.net!news.megapath.net.POSTED!not-for-mail NNTP-Posting-Date: Fri, 08 Dec 2006 19:37:23 -0600 From: "Randy Brukardt" Newsgroups: comp.lang.ada References: <1165585768.342140.201110@16g2000cwy.googlegroups.com> <1165602630.553040.134960@n67g2000cwd.googlegroups.com> Subject: Re: Default comparison of tagged variant records Date: Fri, 8 Dec 2006 19:38:20 -0600 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1807 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 Message-ID: NNTP-Posting-Host: 64.32.209.38 X-Trace: sv3-cKZ9/jEjdEzjGnM13gXMQZHSmRO8sSXePIEPGcZq7siiuAdTeD+owCDUpcNvJNcxh6YX+T/0RVpQiBb!McVm8bFy8nA8a9D0sS485SPDExfQHwWwIhyIE6cU09QeVhn7OlYFBYx2Okdp5d1NgMWkZ1hLBHwv!tFkcvcf3qArS7Q== X-Complaints-To: abuse@megapath.net X-DMCA-Complaints-To: abuse@megapath.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news2.google.com comp.lang.ada:7869 Date: 2006-12-08T19:38:20-06:00 List-Id: "Adam Beneschan" wrote in message news:1165602630.553040.134960@n67g2000cwd.googlegroups.com... > msimonides@power.com.pl wrote: > > I'm having problem with default comparison of tagged, variant records > > not calling user-defined "=" operators for record components. At least > > that's, what I think. > > > > Here is an example: > > > > with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; > > with Ada.Text_IO; use Ada.Text_IO; > > > > procedure Test is > > > > type Thing is tagged > > record > > null; > > end record; > > > > type Bigger_Thing (Discriminant : Boolean) is new Thing with > > record > > case Discriminant is > > when True => > > Text : Unbounded_String; > > when False => > > Number : Natural; > > end case; > > end record; > > > > Big_Something : constant Bigger_Thing := Bigger_Thing'( > > Discriminant => True, Text => Null_Unbounded_String); > > Big_Something_Copy : constant Bigger_Thing := Big_Something; > > > > begin > > Put_Line ("Are they equal?"); > > Put_Line (Boolean'Image (Big_Something = Big_Something_Copy)); > > end Test; > > > > > > It prints "FALSE" and does it for both values of Discriminant, so even > > when Text component isn't used. > > However, comparison works properly when either there is no > > Unbounded_String, the record isn't tagged or the record doesn't have a > > discriminant. > > This looks like a compiler bug to me. It should return TRUE in those > all cases. I agree with Adam that it *looks* like a compiler bug. OTOH, I tried it on Janus/Ada and it also gave FALSE. Something else is going on... ...(much later)... The Janus/Ada issue looks like a compiler bug. The fact that Unbounded_String is not visibly tagged is fooling the compiler into using the predefined rather than the primitive equality. There is code to handle this, but it doesn't work. The direct call to "=" works right. ...(much, much later)... ...and so does the call to "=". Your program should print TRUE and this is clearly a Gnat bug. ;-) (If anyone cares, the problem with Janus/Ada was that it was not picking up the primitive "=" for the untagged private type Unbounded_String, as it was only looking for primitive *dispatching* operations. Thus it was using the predefined one, and that always returned False unless the objects were the same object. Gnat's problem may very well be different.) Randy.