https://gcc.gnu.org/g:98eedbea61d6d56dfa99748c20d4a1683b149c16
commit r16-4737-g98eedbea61d6d56dfa99748c20d4a1683b149c16 Author: Eric Botcazou <[email protected]> Date: Thu Oct 30 15:41:09 2025 +0100 [Ada] Fix formal parameter incorrectly visible from outside of instance 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 exactly the same change to the processing of Collect_Interps for expanded names. gcc/ada/ PR ada/15610 * sem_type.adb (Collect_Interps): Apply the same visibility criterion to expanded names as Find_Expanded_Name. gcc/testsuite/ * gnat.dg/specs/generic_inst7.ads: New test. * gnat.dg/specs/generic_inst8.ads: New test. Diff: --- gcc/ada/sem_type.adb | 11 +++++++---- gcc/testsuite/gnat.dg/specs/generic_inst7.ads | 17 +++++++++++++++++ gcc/testsuite/gnat.dg/specs/generic_inst8.ads | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/gcc/ada/sem_type.adb b/gcc/ada/sem_type.adb index 32d0833f3a82..31a2acdfc646 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; diff --git a/gcc/testsuite/gnat.dg/specs/generic_inst7.ads b/gcc/testsuite/gnat.dg/specs/generic_inst7.ads new file mode 100644 index 000000000000..3132525dc41d --- /dev/null +++ b/gcc/testsuite/gnat.dg/specs/generic_inst7.ads @@ -0,0 +1,17 @@ +-- { 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; diff --git a/gcc/testsuite/gnat.dg/specs/generic_inst8.ads b/gcc/testsuite/gnat.dg/specs/generic_inst8.ads new file mode 100644 index 000000000000..0eac70947235 --- /dev/null +++ b/gcc/testsuite/gnat.dg/specs/generic_inst8.ads @@ -0,0 +1,18 @@ +-- { 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;
