diff mbox series

[Ada] Fix comment of Get_Iterable_Type_Primitive

Message ID 20200617081610.GA55337@adacore.com
State New
Headers show
Series [Ada] Fix comment of Get_Iterable_Type_Primitive | expand

Commit Message

Pierre-Marie de Rodat June 17, 2020, 8:16 a.m. UTC
The comment for Get_Iterable_Type_Primitive didn't mention that it can
be used for primitives Last and Previous. This happens when this routine
is called from Build_Formal_Container_Iteration when analyzing a reverse
iteration.

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

2020-06-17  Piotr Trojanek  <trojanek@adacore.com>

gcc/ada/

	* sem_util.ads, sem_util.adb (Get_Iterable_Type_Primitive): Fix
	comment and enforce it with an assertion in the body.
diff mbox series

Patch

--- gcc/ada/sem_util.adb
+++ gcc/ada/sem_util.adb
@@ -10175,6 +10175,16 @@  package body Sem_Util is
      (Typ : Entity_Id;
       Nam : Name_Id) return Entity_Id
    is
+      pragma Assert
+        (Is_Type (Typ)
+         and then
+         Nam_In (Nam, Name_Element,
+                      Name_First,
+                      Name_Has_Element,
+                      Name_Last,
+                      Name_Next,
+                      Name_Previous));
+
       Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
       Assoc : Node_Id;
 

--- gcc/ada/sem_util.ads
+++ gcc/ada/sem_util.ads
@@ -1126,8 +1126,8 @@  package Sem_Util is
    function Get_Iterable_Type_Primitive
      (Typ : Entity_Id;
       Nam : Name_Id) return Entity_Id;
-   --  Retrieve one of the primitives First, Next, Has_Element, Element from
-   --  the value of the Iterable aspect of a type.
+   --  Retrieve one of the primitives First, Last, Next, Previous, Has_Element,
+   --  Element from the value of the Iterable aspect of a type.
 
    procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id);
    --  Retrieve the fully expanded name of the library unit declared by