diff mbox series

[Ada] Handle IN iterator for class-wide derived object of iterator type

Message ID 20220513080744.GA2512046@adacore.com
State New
Headers show
Series [Ada] Handle IN iterator for class-wide derived object of iterator type | expand

Commit Message

Pierre-Marie de Rodat May 13, 2022, 8:07 a.m. UTC
The compiler currently rejects iterating on an interface type derived
from an iterator type.

See Ada RM 5.5.1(6/3) and 5.5.2(3/3).

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* sem_ch5.adb (Analyze_Iterator_Specification): Fix Typ in the
	case of a class-wide derived iterator.
diff mbox series

Patch

diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -2761,9 +2761,21 @@  package body Sem_Ch5 is
                end;
             end if;
 
-         --  IN iterator, domain is a range, or a call to Iterate function
+         --  IN iterator, domain is a range, a call to Iterate function,
+         --  or an object/actual parameter of an iterator type.
 
          else
+            --  If the type of the name is class-wide and its root type is a
+            --  derived type, the primitive operations (First, Next, etc.) are
+            --  those inherited by its specific type. Calls to these primitives
+            --  will be dispatching.
+
+            if Is_Class_Wide_Type (Typ)
+              and then Is_Derived_Type (Etype (Typ))
+            then
+               Typ := Etype (Typ);
+            end if;
+
             --  For an iteration of the form IN, the name must denote an
             --  iterator, typically the result of a call to Iterate. Give a
             --  useful error message when the name is a container by itself.