https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123289
Bug ID: 123289
Summary: Overloaded subprograms are not correctly resolved
within container aggregates
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ada
Assignee: unassigned at gcc dot gnu.org
Reporter: liam at liampwll dot com
CC: dkm at gcc dot gnu.org
Target Milestone: ---
Within a container aggregate, the Add_Named procedure (and likely all others)
always resolve to the last defined subprogram rather than the subprogram which
matches the argument types. I have tested this on 15.2.1 and the current trunk.
This can be observed using the following test program:
------ json.ads
pragma Ada_2022;
package JSON is
type JSON_Value is tagged null record;
type JSON_Object is new JSON_Value with null record
with Aggregate => (Empty => Empty, Add_Named => Insert);
type JSON_Integer is new JSON_Value with null record
with Integer_Literal => From_Universal_Image;
function Empty return JSON_Object
is (null record);
procedure Insert
(O : in out JSON_Object; Key : String; Value : JSON_Integer'Class)
is null;
-- JSON_Integer'Class may be replaced with Integer and the same bug still
occurs.
procedure Insert (O : in out JSON_Object; Key : String; Value : String)
is null;
function From_Universal_Image (Value : String) return JSON_Integer
is (null record);
end JSON;
----- example.adb
with JSON; use JSON;
procedure Example is
A : JSON_Object := ["a" => "b"];
-- Works if Insert for String is last.
B : JSON_Object := ["a" => 1];
-- Works if Insert for JSON_Integer'Class is last.
begin
A.Insert ("c", 1);
A.Insert ("d", "e");
-- Both of these always work.
end Example;