comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Default comparison of tagged variant records
Date: Fri, 8 Dec 2006 19:38:20 -0600
Date: 2006-12-08T19:38:20-06:00	[thread overview]
Message-ID: <ZOCdnbGHa5HOjufYnZ2dnUVZ_tCtnZ2d@megapath.net> (raw)
In-Reply-To: 1165602630.553040.134960@n67g2000cwd.googlegroups.com

"Adam Beneschan" <adam@irvine.com> 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.






  reply	other threads:[~2006-12-09  1:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-08 13:49 Default comparison of tagged variant records msimonides
2006-12-08 18:30 ` Adam Beneschan
2006-12-09  1:38   ` Randy Brukardt [this message]
2006-12-11  7:40     ` msimonides
2006-12-11 23:12       ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox