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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9cfa83146b0781ed X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-11-17 05:53:30 PST Newsgroups: comp.lang.ada Path: nntp.gmd.de!xlink.net!sol.ctr.columbia.edu!howland.reston.ans.net!swrinde!hookup!news.mathworks.com!noc.near.net!ray.com!news.ray.com!news.ed.ray.com!swlvx2!jgv From: jgv@swl.msd.ray.com (John Volan) Subject: Re: Overloading for T and T'Class Sender: news@swlvx2.msd.ray.com (NEWS USER) Organization: Raytheon Company, Tewksbury, MA Message-ID: References: Date: Wed, 16 Nov 1994 01:22:35 GMT Date: 1994-11-16T01:22:35+00:00 List-Id: In article jgv@swl.msd.ray.com (John Volan) writes: > In Ada9X, is it legal to overload the same subprogram name for both >some tagged type T and its class-wide type T'Class? For example: > > package P is > type T is tagged ... ; > procedure Op (X : in out T); > procedure Op (X : in out T'Class); > ... > end P; > >If this is legal, what would be the ramifications of doing this? >Would it even make any sense to do this? If it did make sense, does >anyone have any thoughts as to where this might turn out to be useful? Thanks to those who sent me private e-mail on this. Summarizing the responses so far: Yes, this does appear to be legal according to the current definition of Ada9X. Apparently, T and T'Class are considered to be different types, even though the set of values of type T'Class "covers" the set of values of type T. That's pretty much what I figured. However, doing this might cause overload resolution problems when you make an invocation: with P; procedure P_Client (X: in out P.T) is begin ... P.Op (X); -- Error in overload resolution -- ambiguous. ... P.Op (P.T'(X)); -- Although maybe these would work? P.Op (P.T'Class'(X)); ... end P_Client; On the other hand, the following doesn't appear to be ambiguous: with P; procedure Another_P_Client (X: in out P.T'Class) is begin ... P.Op (X); -- No problem, only one way to interpret this ... end Another_P_Client; (FYI: GNAT-1.83 seems to like the package spec P, but dies with an assertion failure on an attempt to invoke. (Bug report has been filed.) Anyway, it would be nice to get some human confirmation on this. Tucker, you have the last word: Is this legal?) The other half of my question was whether there was any rationale anyone could suggest for actually making use of this kind of overloading. Personally, I haven't been able to come up with one. On the basis of the ambiguous-invocation problem alone, I'd say that we'd probably want to avoid doing overloadings like these. But does anyone else have any thoughts on this? John Volan -------------------------------------------------------------------------------- -- Me : Person := (Name => "John Volan", -- Company => "Raytheon Missile Systems Division", -- E_Mail_Address => "jgv@swl.msd.ray.com", -- Affiliation => "Enthusiastic member of Team Ada!", -- Humorous_Disclaimer => "These opinions are undefined " & -- "by my employer and therefore " & -- "any use of them would be " & -- "totally erroneous."); --------------------------------------------------------------------------------