The compiler failed to reject a formal package whose name is the same as that
of the generic unit, or its ultimate prefix.
Compiling p-child2.ads must yield:
p-child2.ads:7:43: "Tested" is hidden within declaration of formal package
package P.Child2 is
generic
with package Tested is new P.P1 (<>);
package P1 is
generic
with package Tested is new Tested.P2 (<>);
package P2 is
procedure Proc_2;
end P2;
end P1;
end P.Child2;
---
package P is
generic
package P1 is
generic
package P2 is
procedure Proc;
end P2;
end P1;
end P;
Tested on x86_64-pc-linux-gnu, committed on trunk
2011-08-05 Ed Schonberg <[email protected]>
* sem_ch12.adb (Analyze_Formal_Package_Declaration): reject a formal
package whose name is the same as that of the generic unit, or its
ultimate prefix.
Index: sem_ch12.adb
===================================================================
--- sem_ch12.adb (revision 177437)
+++ sem_ch12.adb (working copy)
@@ -2124,7 +2124,7 @@
return Pack_Decl;
end Build_Local_Package;
- -- Start of processing for Analyze_Formal_Package
+ -- Start of processing for Analyze_Formal_Package_Declaration
begin
Text_IO_Kludge (Gen_Id);
@@ -2182,6 +2182,25 @@
end if;
end if;
+ -- Check that name of formal package does not hide name of generic,
+ -- or its leading prefix. This check must be done separately because
+ -- the name of the generic has already been analyzed.
+
+ declare
+ Gen_Name : Entity_Id;
+
+ begin
+ Gen_Name := Gen_Id;
+ while Nkind (Gen_Name) = N_Expanded_Name loop
+ Gen_Name := Prefix (Gen_Name);
+ end loop;
+ if Chars (Gen_Name) = Chars (Pack_Id) then
+ Error_Msg_NE
+ ("& is hidden within declaration of formal package",
+ Gen_Id, Gen_Name);
+ end if;
+ end;
+
if Box_Present (N)
or else No (Generic_Associations (N))
or else Nkind (First (Generic_Associations (N))) = N_Others_Choice