[Ada] Fix expansion of aggregate for discriminated limited extension
authorEric Botcazou <ebotcazou@adacore.com>
Sat, 23 Apr 2022 10:28:28 +0000 (12:28 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 30 May 2022 08:29:02 +0000 (08:29 +0000)
The presence of the discriminants prevents the values associated with the
components of the parent type from being put into the sub-aggregate built
for the _Parent component.

gcc/ada/

* exp_aggr.adb (Expand_Record_Aggregate.Build_Back_End_Aggregate):
Skip the discriminants at the start of the component list before
looking for the components inherited from the parent in the case
of a tagged extension.

gcc/ada/exp_aggr.adb

index 13be987..4828406 100644 (file)
@@ -8474,11 +8474,21 @@ package body Exp_Aggr is
                   Parent_Name  : Node_Id;
 
                begin
-                  --  Remove the inherited component association from the
-                  --  aggregate and store them in the parent aggregate
-
                   First_Comp   := First (Component_Associations (N));
                   Parent_Comps := New_List;
+
+                  --  First skip the discriminants
+
+                  while Present (First_Comp)
+                    and then Ekind (Entity (First (Choices (First_Comp))))
+                                                               = E_Discriminant
+                  loop
+                     Next (First_Comp);
+                  end loop;
+
+                  --  Then remove the inherited component association from the
+                  --  aggregate and store them in the parent aggregate
+
                   while Present (First_Comp)
                     and then
                       Scope (Original_Record_Component