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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,978302825739789b,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!24g2000hsh.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Another compiler problem related to multiple inheritance? Date: Fri, 11 Apr 2008 00:33:09 -0700 (PDT) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 128.141.45.242 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1207899190 16984 127.0.0.1 (11 Apr 2008 07:33:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 11 Apr 2008 07:33:10 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 24g2000hsh.googlegroups.com; posting-host=128.141.45.242; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:20875 Date: 2008-04-11T00:33:09-07:00 List-Id: 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? 2. How does it influence the ability of the compiler to verify that Concrete implements Middle_2? 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)? In any case, the compiler error might indicate the problem related to what I've found previously - that multiple inheritance of interfaces is not (yet) properly supported. -- Maciej Sobczak * www.msobczak.com * www.inspirel.com