This patch fixes an error in the handling of freeze actions generated for a generic package that is a compilation unit, whose entities carry iterable aspects.
The following must compile quietly: --- generic type Data_Type (<>) is limited private; package Data_Streams is type Root_Data_Stream_Type is abstract tagged limited null record; function Has_Data (Stream : Root_Data_Stream_Type) return Boolean is abstract; function Consume (Stream : not null access Root_Data_Stream_Type) return Data_Type is abstract; generic type Data_Stream_Type is new Root_Data_Stream_Type with private; package Add_Iteration is type Iterable_Data_Stream_Type is new Data_Stream_Type with private with Iterable => (First => First, Next => Next, Has_Element => Has_Element, Element => Element); type Cursor is private; function First (Stream : Iterable_Data_Stream_Type) return Cursor; function Next ( Stream : Iterable_Data_Stream_Type; Position : Cursor ) return Cursor; function Has_Element ( Stream : Iterable_Data_Stream_Type; Position : Cursor ) return Boolean; function Element ( Stream : Iterable_Data_Stream_Type; Position : Cursor ) return Data_Type; private type Reference_Type (Stream : not null access Iterable_Data_Stream_Type) is null record; type Iterable_Data_Stream_Type is new Data_Stream_Type with record Self : Reference_Type (Iterable_Data_Stream_Type'Access); end record; type Cursor is null record; end Add_Iteration; end Data_Streams; --- package body Data_Streams is package body Add_Iteration is function First (Stream : Iterable_Data_Stream_Type) return Cursor is begin return (null record); end First; function Has_Element ( Stream : Iterable_Data_Stream_Type; Position : Cursor ) return Boolean is begin return Has_Data (Stream); end Has_Element; function Next ( Stream : Iterable_Data_Stream_Type; Position : Cursor ) return Cursor is begin return (null record); end Next; function Element ( Stream : Iterable_Data_Stream_Type; Position : Cursor ) return Data_Type is begin return Consume (Stream.Self.Stream); end Element; end Add_Iteration; end Data_Streams; Tested on x86_64-pc-linux-gnu, committed on trunk 2017-05-02 Ed Schonberg <schonb...@adacore.com> * exp_util.adb (Insert_Library_Level_Action): Use proper scope to analyze generated actions. If the main unit is a body, the required scope is that of the corresponding unit declaration.
Index: exp_util.adb =================================================================== --- exp_util.adb (revision 247461) +++ exp_util.adb (working copy) @@ -7491,8 +7491,10 @@ Aux : constant Node_Id := Aux_Decls_Node (Cunit (Main_Unit)); begin - Push_Scope (Cunit_Entity (Main_Unit)); - -- ??? should this be Current_Sem_Unit instead of Main_Unit? + Push_Scope (Cunit_Entity (Current_Sem_Unit)); + -- And not Main_Unit as previously. If the main unit is a body, + -- the scope needed to analyze the actions is the entity of the + -- corresponding declaration. if No (Actions (Aux)) then Set_Actions (Aux, New_List (N));