From: Gary Dismukes <dismu...@adacore.com>

The compiler incorrectly reported a type error on a container aggregate
for a Vector type with a loop_parameter_specification specifying a
nonstatic upper bound, complaining that it expected the Vector index
type, but instead found type Count_Type. The expansion of the aggregate
was incorrectly passing a size temporary of type Count_Type to the
function associated with the New_Indexed part of the container type's
Aggregate aspect (New_Vector in the case of Vectors), which has two
formals of the container index type. The fix is to convert the size
temporary to the expected index type.

gcc/ada/

        * exp_aggr.adb (Expand_Container_Aggregate): Apply a conversion to the
        size temp object passed as the second actual parameter on the call to
        the New_Indexed_Subp function, to convert it to the index type of the
        container type (taken from the first formal parameter of the function).

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_aggr.adb | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 691430a3e52..513fc2ded9a 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -6984,8 +6984,14 @@ package body Exp_Aggr is
                   Parameter_Associations =>
                     New_List (
                       Make_Integer_Literal (Loc, 1),
-                      New_Occurrence_Of
-                        (Defining_Identifier (Siz_Decl), Loc))));
+                      Make_Type_Conversion (Loc,
+                        Subtype_Mark =>
+                          New_Occurrence_Of
+                            (Etype (First_Formal (Entity (New_Indexed_Subp))),
+                             Loc),
+                        Expression => New_Occurrence_Of
+                                        (Defining_Identifier (Siz_Decl),
+                                         Loc)))));
          end if;
 
          Append (Init_Stat, Aggr_Code);
-- 
2.42.0

Reply via email to