[Ada] Spurious accessibility error on "for of" loop parameter
authorJustin Squirek <squirek@adacore.com>
Sat, 27 Feb 2021 19:30:09 +0000 (14:30 -0500)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 16 Jun 2021 08:43:00 +0000 (04:43 -0400)
gcc/ada/

* sem_util.adb (Accessibility_Level): Take into account
renamings of loop parameters.

gcc/ada/sem_util.adb

index 65376b1e1a1f56104e5420d443f7848cd914f1b9..aa2449329cd307ad5f38b9c38f91a83aaa1a5be4 100644 (file)
@@ -664,6 +664,15 @@ package body Sem_Util is
                return Make_Level_Literal
                         (Scope_Depth (Enclosing_Dynamic_Scope (E)) + 1);
 
+            --  Check if E is an expansion-generated renaming of an iterator
+            --  by examining Related_Expression. If so, determine the
+            --  accessibility level based on the original expression.
+
+            elsif Ekind (E) in E_Constant | E_Variable
+              and then Present (Related_Expression (E))
+            then
+               return Accessibility_Level (Related_Expression (E));
+
             --  Normal object - get the level of the enclosing scope
 
             else