diff mbox

[Ada] Rejecting properly illegal iterator

Message ID 20141107134852.GA7127@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Nov. 7, 2014, 1:48 p.m. UTC
This patch removes an infinite loop in the compiler, when an Ada 2012 iterator
is attempted over an object without proper iterable aspects, and the code is
compiled in SPARK mode.

Compiling iter.adb must yield:

iter.adb:12:21: cannot iterate over "R"
iter.adb:12:21: to iterate directly over the elements of a container,
                write "of Obj"

---
procedure Iter is
   pragma SPARK_Mode (On);

   type R is record
     X, Y, Z : Integer;
   end record;

   Obj : R;
   function Sum (X : R) return Integer is
      Result : Integer := 0;
   begin
      return Result : Integer := 0  Do
         for Val in Obj loop
            Result := Result + Val;
         end loop;
      end return;
   end;
begin
   if Sum (Obj) /= 0 then
      null;
   end if;
end;

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

2014-11-07  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch5.adb (Analyze_Iterator_Specification): return if name
	in iterator does not have any usable aspect for iteration.
diff mbox

Patch

Index: sem_ch5.adb
===================================================================
--- sem_ch5.adb	(revision 217215)
+++ sem_ch5.adb	(working copy)
@@ -2063,6 +2063,10 @@ 
                   Error_Msg_NE
                     ("\to iterate directly over the elements of a container, "
                      & "write `of &`", Name (N), Original_Node (Name (N)));
+
+                  --  No point in continuing analysis of iterator spec.
+
+                  return;
                end if;
             end if;