> The fix simply aligns this implementation with the one exercised by
> PR ada/64869, which is more robust.
Except that I overlooked a subtle issue with renamings...
Tested on x86-64/Linux, applied on the mainline.
2025-11-02 Eric Botcazou <[email protected]>
PR ada/52319
* sem_ch8.adb (End_Use_Package): Use the scope of the operator.
2025-11-02 Eric Botcazou <[email protected]>
* gnat.dg/use_type4.adb: New test.
--
Eric Botcazoudiff --git a/sem_ch8.adb b/sem_ch8.adb
index 79983439ec..f251f407d6 100644
--- a/sem_ch8.adb
+++ b/sem_ch8.adb
@@ -5330,11 +5330,6 @@ procedure End_Use_Clauses (Clause : Node_Id) is
---------------------
procedure End_Use_Package (N : Node_Id) is
- Pack : Entity_Id;
- Pack_Name : Node_Id;
- Id : Entity_Id;
- Elmt : Elmt_Id;
-
function Type_In_Use (T : Entity_Id; P : Entity_Id) return Boolean;
-- Check whether type T is declared in P and appears in an active
-- use_type clause.
@@ -5349,6 +5344,14 @@ function Type_In_Use (T : Entity_Id; P : Entity_Id) return Boolean is
return Scope (BT) = P and then (In_Use (T) or else In_Use (BT));
end Type_In_Use;
+ -- Local variables
+
+ Elmt : Elmt_Id;
+ Id : Entity_Id;
+ Pack : Entity_Id;
+ Pack_Name : Node_Id;
+ Scop : Entity_Id;
+
-- Start of processing for End_Use_Package
begin
@@ -5373,17 +5376,20 @@ function Type_In_Use (T : Entity_Id; P : Entity_Id) return Boolean is
-- Preserve use-visibility of operators that are primitive
-- operators of a type that is use-visible through an active
- -- use_type_clause.
+ -- use_type_clause. Note that we compare with the scope of
+ -- the operator and not Pack itself, lest Pack be a renaming.
+
+ Scop := Scope (Id);
if Nkind (Id) = N_Defining_Operator_Symbol
and then
- (Type_In_Use (Etype (Id), Pack)
- or else Type_In_Use (Etype (First_Formal (Id)), Pack)
+ (Type_In_Use (Etype (Id), Scop)
+ or else Type_In_Use (Etype (First_Formal (Id)), Scop)
or else
(Present (Next_Formal (First_Formal (Id)))
and then
Type_In_Use
- (Etype (Next_Formal (First_Formal (Id))), Pack)))
+ (Etype (Next_Formal (First_Formal (Id))), Scop)))
then
null;
else
-- { dg-do compile }
procedure Use_Type4 is
package P1 is
type T is new Integer;
function "and" (L, R : in Integer) return T;
end P1;
package body P1 is
function "and" (L, R : in Integer) return T is
begin
return T (L * R);
end "and";
end P1;
use type P1.T;
package Renaming renames P1;
package P2 is
use Renaming;
end P2;
G : P1.T := Integer'(1) and Integer'(2);
begin
null;
end;