diff mbox series

[Ada] Derived iterable types with noniterable parent

Message ID 20170906102956.GA127480@adacore.com
State New
Headers show
Series [Ada] Derived iterable types with noniterable parent | expand

Commit Message

Arnaud Charlet Sept. 6, 2017, 10:29 a.m. UTC
This patch fixes a bug in which if a derived type has a Default_Iterator
specified, and the parent type does not, then a "for ... of" loop causes
the compiler to crash. No small test case available.

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

2017-09-06  Bob Duff  <duff@adacore.com>

	* exp_ch5.adb (Get_Default_Iterator): Replace
	"Assert(False)" with "return Iter", because if an iterable
	type is derived from a noniterable one, then we won't find an
	overriding or inherited default iterator.
diff mbox series

Patch

Index: exp_ch5.adb
===================================================================
--- exp_ch5.adb	(revision 251767)
+++ exp_ch5.adb	(working copy)
@@ -3934,9 +3934,9 @@ 
 
             function Get_Default_Iterator
               (T : Entity_Id) return Entity_Id;
-            --  If the container is a derived type, the aspect holds the parent
-            --  operation. The required one is a primitive of the derived type
-            --  and is either inherited or overridden. Also sets Container_Arg.
+            --  Return the default iterator for a specific type. If the type is
+            --  derived, we return the inherited or overridden one if
+            --  appropriate.
 
             --------------------------
             -- Get_Default_Iterator --
@@ -3953,11 +3953,11 @@ 
             begin
                Container_Arg := New_Copy_Tree (Container);
 
-               --  A previous version of GNAT allowed indexing aspects to
-               --  be redefined on derived container types, while the
-               --  default iterator was inherited from the parent type.
-               --  This non-standard extension is preserved temporarily for
-               --  use by the modelling project under debug flag d.X.
+               --  A previous version of GNAT allowed indexing aspects to be
+               --  redefined on derived container types, while the default
+               --  iterator was inherited from the parent type. This
+               --  nonstandard extension is preserved for use by the
+               --  modelling project under debug flag -gnatd.X.
 
                if Debug_Flag_Dot_XX then
                   if Base_Type (Etype (Container)) /=
@@ -3995,9 +3995,11 @@ 
                      Next_Elmt (Prim);
                   end loop;
 
-                  --  Default iterator must exist
+                  --  If we didn't find it, then our parent type is not
+                  --  iterable, so we return the Default_Iterator aspect of
+                  --  this type.
 
-                  pragma Assert (False);
+                  return Iter;
 
                --  Otherwise not a derived type