]> gcc.gnu.org Git - gcc.git/commitdiff
ada: Apply correct element type for container aggregates
authorViljar Indus <indus@adacore.com>
Wed, 5 Jul 2023 11:21:50 +0000 (14:21 +0300)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 18 Jul 2023 13:11:47 +0000 (15:11 +0200)
When dealing with a container aggregate with an iterator
specification the iterator should take the value of the
element of the container instead of the key.

gcc/ada/

* sem_aggr.adb (Resolve_Iterated_Association): Use the element
type for the iterator in a container aggregate with an iterator
specification.

gcc/ada/sem_aggr.adb

index 5bfbde5052b83e7e5ac3604c7d52ddd445b4e44f..ecd508a66f8292a1eacee84465d188825f4d523f 100644 (file)
@@ -3228,6 +3228,8 @@ package body Sem_Aggr is
             Analyze_And_Resolve (New_Copy_Tree (Key_Expr), Key_Type);
             End_Scope;
 
+            Typ := Key_Type;
+
          elsif Present (Iterator_Specification (Comp)) then
             Copy    := Copy_Separate_Tree (Iterator_Specification (Comp));
             Id_Name :=
@@ -3252,7 +3254,7 @@ package body Sem_Aggr is
 
                elsif Present (Key_Type) then
                   Analyze_And_Resolve (Choice, Key_Type);
-
+                  Typ := Key_Type;
                else
                   Typ := Etype (Choice);  --  assume unique for now
                end if;
@@ -3282,12 +3284,8 @@ package body Sem_Aggr is
 
          Enter_Name (Id);
 
-         if No (Key_Type) then
-            pragma Assert (Present (Typ));
-            Set_Etype (Id, Typ);
-         else
-            Set_Etype (Id, Key_Type);
-         end if;
+         pragma Assert (Present (Typ));
+         Set_Etype (Id, Typ);
 
          Mutate_Ekind (Id, E_Variable);
          Set_Is_Not_Self_Hidden (Id);
This page took 0.067083 seconds and 5 git commands to generate.