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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Generic oddness Date: Sun, 12 Apr 2020 18:38:07 +0200 Organization: A noiseless patient Spider Message-ID: <874ktofymo.fsf@samuel> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="c3c0a238e299f89f2b95fec2e65065be"; logging-data="7374"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19e6ys8PZproLV6r7+XVC9y" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cancel-Lock: sha1:WRr16vL4FZuvfBWpwFbGpZ2lVpM= sha1:TipzjcSRgDv3s8fJI5vyZpAhDQI= Xref: reader01.eternal-september.org comp.lang.ada:58349 Date: 2020-04-12T18:38:07+02:00 List-Id: Per Jakobsen writes: > Declaring the package List_Type from Doubly_Linked_Lists gives me > "abstract subprogram not allowed as generic actual" unless I declare > the "A_Intf" type in a package separate from the List_Type > declaration, or if I instantiate a workaround (dummy) generic before > (as in the below MWE): > > --- gnatchop --------------------- > generic > type A is private; > package Gen is > pragma Pure; > end Gen; > package Intf is > type Intf_Type is interface; > procedure Do_Stuff (I : in out Intf_Type) is abstract; > end Intf; > with Ada.Containers.Doubly_Linked_Lists; > with Intf; > with Gen; > > package Test is > use Intf; > > type A_Intf is new Intf_Type with > record > A : Natural; > end record; > > overriding > procedure Do_Stuff (I : in out A_Intf); > > package Workaround is new Gen (A => A_Intf); > -- Commenting the above line will cause the > -- next line to fail !?!? > package List_Type is > new Ada.Containers.Doubly_Linked_Lists (Element_Type => A_Intf, > "=" => "="); > end Test; > package body Test is > > overriding > procedure Do_Stuff (I : in out A_Intf) is > begin > null; > end Do_Stuff; > > end Test; > --- gnatchop end --------------------- > > Unpack with gnatchop, then compile with gnatmake test.adb. Then > comment the Workaround package instantiation and recompile. > > Using GNATMAKE Community 2019 (20190517-83). > > Is there a sane explanation for this behavior? I think I have a partial explanation. Instantiating the package Gen freezes the type Test.A_Intf. Similarly, if you declare A_Intf in a package and then instantiate Doubly_Linked_Lists in another package, the instantiation of Doubly_Linked_Lists sees a frozen type as the actual. The part that I don't understand is why you can instantiate Gen but not Doubly_Linked_Lists with the same actual type as parameter; I think the instantiation of Doubly_Linked_Lists should freeze the type A_Intf just like package Workaround does. -- Ludovic Brenta. Multi-channel structures transfer the thinkers/planners throughout the organization. In the same time, the enabler will be well equipped to harness an alternative.