ada: Compiler error reporting illegal prefix on legal loop iterator with "in"
31 October 2023 at 19:50
ada: Compiler error reporting illegal prefix on legal loop iterator with "in" During semantic analysis, the compiler fails to determine the cursor type in the case of a generalized iterator loop with "in", in the case where the iterator type has a parent type that is a controlled type (for example) and its ancestor iterator interface type is given after as a progenitor. It also improperly determines the ancestor interface type during expansion (within Expand_Iterator_Loop_Over_Container), for both "in" and "of" iterator forms. The FE was assuming that the iterator interface is simply the parent type of the iterator type, but that type can occur later in the interface list, or be inherited. A new function is added that properly locates a type's iterator interface ancestor, if any, and is called for analysis and expansion. gcc/ada/ * exp_ch5.adb (Expand_Iterator_Loop_Over_Container): Retrieve the iteration type's iteration interface progenitor via Iterator_Interface_Ancestor, in the case of both "in" and "of" iterators. Narrow the scope of Pack, so it's declared and initialized only within the code related to "of" iterators, and change its name to Cont_Type_Pack. Adjust comments. * sem_ch5.adb (Get_Cursor_Type): In the case of a derived type, retrieve the iteration type's iterator interface progenitor (if it exists) via Iterator_Interface_Ancestor rather than assuming that the parent type is the interface progenitor. * sem_util.ads (Iterator_Interface_Ancestor): New function. * sem_util.adb (Iterator_Interface_Ancestor): New function returning a type's associated iterator interface type, if any, by collecting and traversing the type's interfaces.