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,b2e3f0346403c575,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!API-DIGITAL.COM-a2kHrUvQQWlmc!not-for-mail Date: Sun, 18 Jul 2010 08:25:36 -0500 From: "Marc A. Criley" User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.10) Gecko/20100527 Thunderbird/3.0.5 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Dispatching confusion Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: X-Complaints-To: abuse@usenetserver.com Organization: UseNetServer.com X-Trace: a31c64c430064e69feb5f04498 Xref: g2news1.google.com comp.lang.ada:12459 Date: 2010-07-18T08:25:36-05:00 List-Id: I'm by why this bit of class-wide dispatching I'm trying to use isn't compiling. Granted, I haven't used it much over the years, but it seemed pretty straightforward. I've concocted a representative example that exhibits the problem, and so I would appreciate a pointer to what I'm missing here. This example simple declares an abstract type, then then derives two child types from it. A Dispatcher procedure taking the class-wide form of the abstract type is declared that invokes a procedure defined for each of the two child types, the atual one being determined at run time, depending on the concrete type of the argument. However, GNAT GPL 2010 (Ubuntu 10.04) refuses to compile this, citing an argument/parameter type mismatch. I'm sure it's right, but I don't understand why. Marc A. Criley ------------------------------------------------------------- package Wrack_Machinery is type Wrack_Base is abstract tagged null record; procedure Dispatcher(W : Wrack_Base'Class); type Wrack_Client_Base is new Wrack_Base with null record; procedure Crank(WC : Wrack_Client_Base); type Wrack_Pub_Base is new Wrack_Base with null record; procedure Crank (WP : Wrack_Pub_Base); end Wrack_Machinery; with Text_IO; use Text_IO; package body Wrack_Machinery is procedure Dispatcher(W : Wrack_Base'Class) is begin Crank(W); end Dispatcher; procedure Crank(WC : Wrack_Client_Base) is begin Put_Line("Client Crank"); end Crank; procedure Crank (WP : Wrack_Pub_Base) is begin Put_Line("Pub Crank"); end Crank; end Wrack_Machinery; with Wrack_Machinery; procedure Wrack_Main is Client : Wrack_Machinery.Wrack_Client_Base; Pub : Wrack_Machinery.Wrack_Pub_Base; begin Wrack_Machinery.Dispatcher(Client); Wrack_Machinery.Dispatcher(Pub); end Wrack_Main; ----------------------------------------------------- $ gnatmake wrack_main gcc -c wrack_main.adb gcc -c wrack_machinery.adb wrack_machinery.adb:7:07: no candidate interpretations match the actuals: wrack_machinery.adb:7:13: expected type "Wrack_Pub_Base" defined at wrack_machinery.ads:11 wrack_machinery.adb:7:13: found type "Wrack_Base'Class" defined at wrack_machinery.ads:3 wrack_machinery.adb:7:13: ==> in call to "Crank" at wrack_machinery.ads:13 wrack_machinery.adb:7:13: ==> in call to "Crank" at wrack_machinery.ads:9 gnatmake: "wrack_machinery.adb" compilation error