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,978302825739789b X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!n14g2000pri.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Another compiler problem related to multiple inheritance? Date: Fri, 11 Apr 2008 09:30:20 -0700 (PDT) Organization: http://groups.google.com Message-ID: <746e6382-32bd-47ab-a858-e021c7b80f66@n14g2000pri.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1207931420 19232 127.0.0.1 (11 Apr 2008 16:30:20 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 11 Apr 2008 16:30:20 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: n14g2000pri.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:20880 Date: 2008-04-11T09:30:20-07:00 List-Id: On Apr 11, 12:33 am, Maciej Sobczak wrote: > Consider the following: > > -- types.ads: > generic > type T is private; > package Types is > > type Base is interface; > > function "=" (Left : Base; > Right : Base) return Boolean is abstract; > > -- Note: diamond-shaped hierarchy: > > type Middle_1 is interface and Base; > type Middle_2 is interface and Base; > type Middle is interface and Middle_1 and Middle_2; > > end Types; > > -- types-concrete_types.ads: > generic > package Types.Concrete_Types is > > type Concrete is new Middle with null record; > > overriding > function "=" (Left : Concrete; Right : Concrete) return Boolean; > > end Types.Concrete_Types; > > -- types-concrete_types.adb: > package body Types.Concrete_Types is > function "=" (Left : Concrete; > Right : Concrete) return Boolean is > begin > return True; > end "="; > end Types.Concrete_Types; > > -- processing.ads: > with Types; > package Processing is > > generic > type Element_Type is private; > with package Some_Types is new Types (T => Element_Type); > type Middle_1_Type (<>) is new Some_Types.Middle_1 with private; > type Middle_2_Type (<>) is new Some_Types.Middle_2 with private; > procedure Do_Something (A : in Middle_1_Type; > B : in Middle_2_Type); > > end Processing; > > -- processing.adb: > package body Processing is > > procedure Do_Something (A : in Middle_1_Type; > B : in Middle_2_Type) is > begin > null; > end Do_Something; > > end Processing; > > -- main.adb: > with Types.Concrete_Types; > with Processing; > procedure Main is > > package My_Types is new Types (T => Integer); > package My_Concrete_Types is new My_Types.Concrete_Types; > > use My_Concrete_Types; > > procedure My_Do_Something is new Processing.Do_Something > (Element_Type => Integer, > Some_Types => My_Types, > Middle_1_Type => Concrete, > Middle_2_Type => Concrete); -- here is the problem > > begin > null; > end Main; > > To sum it up: there is a diamond-shaped interface hierarchy. The > Concrete type derives indirectly from both Middle_1 and Middle_2. > The instantiation of Do_Something in Main fails at the point marked > above with the following: > > $ gnatmake main > gcc -c main.adb > main.adb:14:24: (Ada 2005) expected type implementing "Middle_2" in > instantiation > gnatmake: "main.adb" compilation error > $ > > This error message is misleading, because obviously Concrete > implements Middle_2 (just as it implements Middle_1 - this is > symmetric). > > An interesting part is that after removing function "=" from the Base > interface, everything compiles fine, which brings more questions: > > 1. How is it possible that function "=" in Concrete compiled? It is > marked as overriding. What it is overriding? The default comparison > operation? Yes. (The language refers to it as the "predefined" equality operator, rather than "default".) The language rules say that this operator must be overridden for Concrete, because the operation of the parent type is abstract. > 2. How does it influence the ability of the compiler to verify that > Concrete implements Middle_2? One would have to look at the compiler source to answer that. This looks like just a bug. The compiler doesn't do things right in that particular case. > 3. Is function "=" in Base correct anyway? Will it dispatch properly > when calling via class-wide Base'Class (assuming that Left and Right > always have the same tag)? Yes. -- Adam