From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Generic oddness
Date: Sun, 12 Apr 2020 18:38:07 +0200
Date: 2020-04-12T18:38:07+02:00 [thread overview]
Message-ID: <874ktofymo.fsf@samuel> (raw)
In-Reply-To: d2fedfee-ff14-40c4-bdfc-87c70d66281e@googlegroups.com
Per Jakobsen <pdj@knaldgas.dk> 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.
next prev parent reply other threads:[~2020-04-12 16:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-12 12:32 Generic oddness Per Jakobsen
2020-04-12 16:38 ` Ludovic Brenta [this message]
2020-04-14 9:42 ` SOLVED: " Per Jakobsen
2020-04-12 18:11 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox