This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Better error message for illegal iterator expression


This patch improves the error message on an iterator specification whose name
is a function call that does not yield a type that implements an iterator
interface.

Compiling try_containers.adb must yield:

   try_containers.adb:17:18: expect object that implements iterator interface

--
with Ada.Text_Io; use Ada.Text_Io;
with Ada.Containers.Vectors;
procedure Try_Containers
is
   package Integer_Vectors is new Ada.Containers.Vectors (Natural, Integer);
   use Integer_Vectors;

   A : Vector := To_Vector (1, 10);
begin
   Loop_1 :
   for Element of A loop
      Put_Line ("A (i) => " & Integer'Image (Element));
      -- can't do Element := 2;
   end loop Loop_1;

   Loop_2 :
   for Cursor in First (A) loop -- oops! should be:
   --  for Cursor in Iterate (A) loop

      Put_Line ("A (I) => " & Integer'Image (Element (Cursor)));
      Replace_Element (A, Cursor, 2);
      Reference (A, Cursor) := 2;
   end loop Loop_2;

end Try_Containers;

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

2014-10-17  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch5.adb (Analyze_Iterator_Specification): If the domain
	of iteration is given by an expression that is not an array type,
	verify that its type implements an iterator iterface.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]