I thought I understood interface and tagged types pretty well, but apparently not!
learn.adacore.com has an example on interfaces that makes sense and compiles, etc. Once I get beyond that relatively trivial example, however, things fall apart.
I think this is as MWE as I can get:
-- from the interface
type A is abstract tagged null record;
type B is new A with private; -- private part has a String
type C is new A with private; -- private part has a vector of A's
type I is interface;
procedure AI (First : A'Class; Second : I) is abstract;
type I2 is new I with null record;
-- procedure AI (First : A'Class; Second : I2);
procedure AI (First : B'Class; Second : I2);
procedure AI (First : C'Class; Second : I2);
-- from the implementation
procedure AI (First : A'Class; Second : I2) is
begin
IO.Put_Line ("AI with A and I2");
end AI;
procedure AI (First : B'Class; Second : I2) is
begin
IO.Put_Line ("AI with B and I2");
end AI;
procedure AI (First : C'Class; Second : I2) is
begin
IO.Put_Line ("AI with C and I2");
end AI;
A program with this fails to compile with this message:
my_interfaces.adb:6:10: error: ambiguous call to "Ai"
my_interfaces.adb:6:10: error: possible interpretation at my_interface.ads:16
my_interfaces.adb:6:10: error: possible interpretation (inherited) at my_interface.ads:13
my_interface.ads:13:10: error: type must be declared abstract or "Ai" overridden
my_interface.ads:13:10: error: "Ai" has been inherited from subprogram at line 11
- The error on line 13 goes away if I implement procedure
AI (A'Class; I)
. I don’t understand why it wants that. - The error on line 6 doesn’t go away no matter what I do, and I don’t understand what’s ambiguous. It’s referring to the abstract procedure (which it shouldn’t even attempt to use…?) and to the actual implementation.
Thanks for any help you can give!
Added later: I just closed something like 20 tabs that I had open last night, trying to make sense of this. So if it turns out to be something truly simple I’ll be myself for weeks.