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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,294c152109d75b4d,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-22 16:13:43 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: adam@irvine.com (Adam Beneschan) Newsgroups: comp.lang.ada Subject: Dispatching and generics - language lawyer question Date: 22 Jul 2002 16:13:43 -0700 Organization: http://groups.google.com/ Message-ID: NNTP-Posting-Host: 66.126.103.122 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1027379623 18476 127.0.0.1 (22 Jul 2002 23:13:43 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 22 Jul 2002 23:13:43 GMT Xref: archiver1.google.com comp.lang.ada:27318 Date: 2002-07-22T23:13:43+00:00 List-Id: I have a couple questions about what's supposed to happen when a generic is instantiated with a class-wide type as an actual type. I'm hoping that someone who really understands the intricacies of the language will be kind enough to answer, and provide chapter and verse from the RM to explain the correct answer. (1) What is the correct output of the program below? (2) What would be the correct output if "private" in line [A] is changed to "tagged private"? I'm pretty sure the answer to (1) is FALSE, since the "=" on line [B] in the instance denotes the predefined "=" declared for T1 in the generic, and not the "=" "defined" for the class-wide type, by 8.3(13). I'm less clear about the answer to (2). Here, the "=" implicitly declared for T1 is a dispatching operation, and thus should dispatch if a controlling operand is of a class-wide type (3.9.2(5)), but it's not clear to me whether the operands in this case are treated as if they were of the formal type (which is not class-wide) or of the actual type (which is class-wide). Thanks in advance for your help. -- Adam generic type T1(<>) is private; -- [A] package Pak1 is type T1_Access is access T1; function Check_Equal (X, Y : T1_Access) return boolean; end Pak1; package body Pak1 is function Check_Equal (X, Y : T1_Access) return boolean is begin return X.all = Y.all; -- [B] end Check_Equal; end Pak1; package Pak2 is type Root_Type is tagged record F1 : Integer; end record; end Pak2; with Pak2; package Pak3 is type Child is new Pak2.Root_Type with record F2 : Integer; end record; function "=" (Left, Right : Child) return boolean; end Pak3; package body Pak3 is function "=" (Left, Right : Child) return boolean is begin return Left.F1 = Right.F1 and then abs Left.F2 = abs Right.F2; end "="; end Pak3; with Pak1; with Pak2; with Pak3; with Text_IO; procedure Test62 is package Pak1_Inst is new Pak1 (Pak2.Root_Type'Class); A1 : Pak1_Inst.T1_Access; A2 : Pak1_Inst.T1_Access; B : Boolean; begin A1 := new Pak3.Child' (F1 => 4, F2 => 6); A2 := new Pak3.Child' (F1 => 4, F2 => -6); B := Pak1_Inst.Check_Equal (A1, A2); Text_IO.Put_Line (Boolean'Image (B)); end Test62;