This patch sets properly the scope of an anonymous access type created for an access to class-wide type declaration in a child unit. Previously the scope was set to the parent unit, leading to anomalous behavior in the back end.
The following must compile quietly in Ada 2005 mode: --- package Parent is end; --- package Parent.Child is type Employee is abstract tagged private; type myBosses_Type_Array is array (Integer range <>) of access Employee'Class; type myBosses_Type is access all myBosses_Type_Array; private type Employee is abstract tagged record myBosses : myBosses_Type; end record; end; --- Tested on x86_64-pc-linux-gnu, committed on trunk 2011-09-05 Ed Schonberg <schonb...@adacore.com> * sem_ch3.adb (Access_Definition): If an access type declaration appears in a child unit, the scope of whatever anonymous type may be generated is the child unit itself.
Index: sem_ch3.adb =================================================================== --- sem_ch3.adb (revision 178542) +++ sem_ch3.adb (working copy) @@ -772,10 +772,16 @@ Anon_Scope := Scope (Defining_Entity (Related_Nod)); end if; + -- For an access type definition, if the current scope is a child + -- unit it is the scope of the type. + + elsif Is_Compilation_Unit (Current_Scope) then + Anon_Scope := Current_Scope; + + -- For access formals, access components, and access discriminants, the + -- scope is that of the enclosing declaration, + else - -- For access formals, access components, and access discriminants, - -- the scope is that of the enclosing declaration, - Anon_Scope := Scope (Current_Scope); end if;