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,461276586f65363c,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!u72g2000cwu.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Predefined equality, reemergence Date: 4 Apr 2006 12:30:13 -0700 Organization: http://groups.google.com Message-ID: <1144179013.753791.169830@u72g2000cwu.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1144179018 21714 127.0.0.1 (4 Apr 2006 19:30:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 4 Apr 2006 19:30:18 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040805 Netscape/7.2,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: u72g2000cwu.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news1.google.com comp.lang.ada:3720 Date: 2006-04-04T12:30:13-07:00 List-Id: Hi, everyone, I'm having trouble understanding how the language rules about predefined equality, specifically 4.5.2(24), behave when the component type involved may be seen as "tagged" or "untagged" depending on whether you're inside an instance. Specifically, with regard to the program below: I would think that the program would set Bool_1 to FALSE and Bool_2 to TRUE. The way the rules look to me, there's an implicit "=" declared in the generic for Rec, and this "=" would be the predefined equality for Rec, which, when matching components, uses the *predefined* (not the primitive) equals for the matching component Comp1, since the formal type T is untagged. The definition of Equal would use this version of "=". Then, in the instance, this implicit "=" is copied, and since Equal would use the implicit "=", it should return FALSE when given two records whose Comp1.Comp2 are different (5 and -5). However, 12.3 says a whole new set of primitive subprograms is implicitly declared for use outside the instance, and it would differ since the type Rec in the instance depends on the properties of the actual type Tagged_Rec, and I would think that "="(Left,Right:Rec) is one of those primitive subprograms that would differ; thus, outside the instance, "=" would refer to the predefined equality that calls the *primitive* equals operator on the component Comp1, since (outside the instance) the component type is tagged, and thus the user-defined "=" would be called, which would return TRUE if the absolute values of Comp2 are the same. When compiled with the version of GNAT I'm using (which is not the latest version), the program sets both Bool_1 and Bool_2 to TRUE, which is not what I expected. What's the correct output? What's my mistake, if any, in interpreting the rules? Thanks for any help you can provide, -- Adam generic type T is private; package Pak1 is type Rec is record Comp1 : T; end record; function Equal (Left, Right : Rec) return Boolean; end Pak1; package body Pak1 is function Equal (Left, Right : Rec) return Boolean is begin return Left = Right; end Equal; end Pak1; package Pak2 is type Tagged_Rec is tagged record Comp2 : Integer; end record; function "=" (Left, Right : Tagged_Rec) return Boolean; end Pak2; package body Pak2 is function "=" (Left, Right : Tagged_Rec) return Boolean is begin return abs (Left.Comp2) = abs (Right.Comp2); end "="; end Pak2; with Pak1; with Pak2; with Text_IO; procedure Test69 is package New_Pak1 is new Pak1 (Pak2.Tagged_Rec); X : New_Pak1.Rec := (Comp1 => (Comp2 => 5)); Y : New_Pak1.Rec := (Comp1 => (Comp2 => -5)); Bool_1 : Boolean := New_Pak1.Equal (X, Y); Bool_2 : Boolean := New_Pak1."=" (X, Y); begin Text_IO.Put_Line (Boolean'Image (Bool_1)); Text_IO.Put_Line (Boolean'Image (Bool_2)); end Test69;