The problem had been partially fixed two decades ago and the original testcase
correctly rejected, but almost 4 years later the submitter made a small tweak
to it which exposed the issue again...
The original fix was a change to Find_Expanded_Name, this additional fix is to
make the same change to the processing of Collect_Interps for expanded names.
Tested on x86-64/Linux, applied on the mainline.
2025-10-30 Eric Botcazou <[email protected]>
PR ada/15610
* sem_type.adb (Collect_Interps): Apply the same visibility
criterion to expanded names as Find_Expanded_Name.
2025-10-30 Eric Botcazou <[email protected]>
* gnat.dg/specs/generic_inst7.ads: New test.
* gnat.dg/specs/generic_inst8.ads: New test.
--
Eric Botcazoudiff --git a/gcc/ada/sem_type.adb b/gcc/ada/sem_type.adb
index 32d0833f3a8..0d13765c31c 100644
--- a/gcc/ada/sem_type.adb
+++ b/gcc/ada/sem_type.adb
@@ -610,14 +610,17 @@ package body Sem_Type is
First_Interp := All_Interp.Last;
Add_One_Interp (N, Ent, Etype (N));
- -- For expanded name, pick up all additional entities from the
- -- same scope, since these are obviously also visible. Note that
- -- these are not necessarily contiguous on the homonym chain.
+ -- For an expanded name, pick up additional visible entities from
+ -- the same scope. Note that these are not necessarily contiguous
+ -- on the homonym chain.
if Nkind (N) = N_Expanded_Name then
H := Homonym (Ent);
while Present (H) loop
- if Scope (H) = Scope (Entity (N)) then
+ if Scope (H) = Scope (Entity (N))
+ and then (not Is_Hidden (H)
+ or else Is_Immediately_Visible (H))
+ then
Add_One_Interp (N, H, Etype (H));
end if;
-- { dg-do compile }
package Generic_Inst7 is
function F return Integer is (0);
generic
with function Foo return Integer;
package P is
type Color is (Foo);
end P;
package My_P is new P (F);
I : Integer := My_P.Foo; -- { dg-error "expected type|found type" }
end Generic_Inst7;
-- { dg-do compile }
package Generic_Inst8 is
function F return Integer is (0);
generic
with function Foo return Integer;
package P is
type Color1 is (Foo);
type Color2 is (Foo);
end P;
package My_P is new P (F);
I : Integer := My_P.Foo; -- { dg-error "no visible interpretation|use" }
end Generic_Inst8;