From 4fa6e820b28b176b2cd5b63f7b04bbba9c88469e Mon Sep 17 00:00:00 2001 From: Romain Beguet Date: Wed, 24 Jan 2024 17:25:51 +0100 Subject: [PATCH 01/11] Use built-in routine to shed rebindings instead of a buggy handmade one. --- ada/ast.py | 25 ++-- .../attr_function_from_generic/test.adb | 22 ++++ .../attr_function_from_generic/test.out | 118 ++++++++++++++++++ .../attr_function_from_generic/test.yaml | 3 + 4 files changed, 150 insertions(+), 18 deletions(-) create mode 100644 testsuite/tests/name_resolution/attr_function_from_generic/test.adb create mode 100644 testsuite/tests/name_resolution/attr_function_from_generic/test.out create mode 100644 testsuite/tests/name_resolution/attr_function_from_generic/test.yaml diff --git a/ada/ast.py b/ada/ast.py index ffa3355fa..467958e2a 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -20080,24 +20080,13 @@ def designated_type(): # However, all of Entity's rebinding may not be relevant. For example, # if `target_type` is the definition of `Standard.Boolean`, no # rebindings will ever be relevant. - # In order to find which rebindings are relevant, we first need to - # find the closest rebindable parent of `target_type`. From there, we - # can inspect Entity's rebindings, and retrieve them as soon as we find - # a parent rebinding that rebinds the closest rebindable parent of - # `target_type`. - - # First we need to find the closest rebindable parent - gd = Var(Self.target_type.parents.find( - lambda p: p.is_a(GenericDecl) - ).cast(GenericDecl).as_bare_entity) - - # Extract the relevant rebindings - relevant_rebindings = Var(gd._.unshed_rebindings( - Entity.info.rebindings - ).then( - lambda fixed: fixed.info.rebindings, - default_val=No(T.EnvRebindings) - )) + # Hence we use the built-in `shed_rebindings` construct from the type + # definition's lexical environment so as to only keep relevant ones. + relevant_rebindings = Var( + Self.target_type.children_env.shed_rebindings( + Entity.info + ).rebindings + ) # Return a rebound `target_type` return T.BaseTypeDecl.entity.new( diff --git a/testsuite/tests/name_resolution/attr_function_from_generic/test.adb b/testsuite/tests/name_resolution/attr_function_from_generic/test.adb new file mode 100644 index 000000000..ac5d0f4cd --- /dev/null +++ b/testsuite/tests/name_resolution/attr_function_from_generic/test.adb @@ -0,0 +1,22 @@ +procedure Test is + generic + type T is (<>); + package Fail_G is + function F (E : T) return T is (T'Val (1)); + end Fail_G; + + generic + package Level_1 is + generic + type Type_T is (<>); + package Level_2 is + package Inst is new Fail_G (Type_T); + end Level_2; + end Level_1; + + package Origin is new Level_1; + pragma Test_Statement; +begin + null; +end Test; + diff --git a/testsuite/tests/name_resolution/attr_function_from_generic/test.out b/testsuite/tests/name_resolution/attr_function_from_generic/test.out new file mode 100644 index 000000000..e98f0a1c9 --- /dev/null +++ b/testsuite/tests/name_resolution/attr_function_from_generic/test.out @@ -0,0 +1,118 @@ +Analyzing test.adb +################## + +Resolving xrefs for node +************************************************************************************* + +Expr: + references: + type: None + expected type: None +Traversing generic node <| GenericPackageDecl ["Level_1"] test.adb:8:4-15:16 [test.adb:17:4] |> +*********************************************************************************************** + +Resolving xrefs for node <| FormalTypeDecl ["Type_T"] test.adb:11:10-11:30 [test.adb:17:4] |> +********************************************************************************************* + + +Resolving xrefs for node <| GenericPackageInstantiation ["Inst"] test.adb:13:10-13:46 [test.adb:17:4] |> +******************************************************************************************************** + +Expr: <| Id "Fail_G" test.adb:13:30-13:36 [test.adb:17:4] |> + references: + type: None + expected type: None +Expr: <| Id "Type_T" test.adb:13:38-13:44 [test.adb:17:4] |> + references: <| DefiningName "Type_T" test.adb:11:15-11:21 [test.adb:17:4] |> + type: None + expected type: None +Traversing generic node <| GenericPackageDecl ["Fail_G"] test.adb:2:4-6:15 [test.adb:17:4, test.adb:13:10] |> +************************************************************************************************************* + +Resolving xrefs for node <| FormalTypeDecl ["T"] test.adb:3:7-3:22 [test.adb:17:4, test.adb:13:10] |> +***************************************************************************************************** + + +Resolving xrefs for node <| ExprFunction ["F"] test.adb:5:7-5:50 [test.adb:17:4, test.adb:13:10] |> +*************************************************************************************************** + +Expr: <| ParenExpr test.adb:5:38-5:49 [test.adb:17:4, test.adb:13:10] |> + type: <| FormalTypeDecl ["Type_T"] test.adb:11:10-11:30 [test.adb:17:4] |> + expected type: <| FormalTypeDecl ["Type_T"] test.adb:11:10-11:30 [test.adb:17:4] |> +Expr: <| CallExpr test.adb:5:39-5:48 [test.adb:17:4, test.adb:13:10] |> + references: <| SyntheticDefiningName "val" test.adb:11:10-11:30 [test.adb:17:4] |> + type: <| FormalTypeDecl ["Type_T"] test.adb:11:10-11:30 [test.adb:17:4] |> + expected type: <| FormalTypeDecl ["Type_T"] test.adb:11:10-11:30 [test.adb:17:4] |> +Expr: <| AttributeRef test.adb:5:39-5:44 [test.adb:17:4, test.adb:13:10] |> + references: <| SyntheticDefiningName "val" test.adb:11:10-11:30 [test.adb:17:4] |> + type: None + expected type: None +Expr: <| Id "T" test.adb:5:39-5:40 [test.adb:17:4, test.adb:13:10] |> + references: <| DefiningName "Type_T" test.adb:11:15-11:21 [test.adb:17:4] |> + type: None + expected type: None +Expr: <| Id "Val" test.adb:5:41-5:44 [test.adb:17:4, test.adb:13:10] |> + references: None + type: None + expected type: None +Expr: <| Int test.adb:5:46-5:47 [test.adb:17:4, test.adb:13:10] |> + references: None + type: + expected type: + +Resolving xrefs for node <| SubpSpec test.adb:5:7-5:34 [test.adb:17:4, test.adb:13:10] |> +***************************************************************************************** + +Expr: <| Id "T" test.adb:5:33-5:34 [test.adb:17:4, test.adb:13:10] |> + references: <| DefiningName "Type_T" test.adb:11:15-11:21 [test.adb:17:4] |> + type: None + expected type: None + +Resolving xrefs for node <| ParamSpec ["E"] test.adb:5:19-5:24 [test.adb:17:4, test.adb:13:10] |> +************************************************************************************************* + +Expr: <| Id "T" test.adb:5:23-5:24 [test.adb:17:4, test.adb:13:10] |> + references: <| DefiningName "Type_T" test.adb:11:15-11:21 [test.adb:17:4] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:6:8-6:14 [test.adb:17:4, test.adb:13:10] |> +**************************************************************************************** + +Expr: <| EndName test.adb:6:8-6:14 [test.adb:17:4, test.adb:13:10] |> + references: <| DefiningName "Inst" test.adb:13:18-13:22 [test.adb:17:4] |> + type: None + expected type: None +Expr: <| Id "Fail_G" test.adb:6:8-6:14 [test.adb:17:4, test.adb:13:10] |> + references: <| DefiningName "Inst" test.adb:13:18-13:22 [test.adb:17:4] |> + type: None + expected type: None + + +Resolving xrefs for node <| EndName test.adb:14:11-14:18 [test.adb:17:4] |> +*************************************************************************** + +Expr: <| EndName test.adb:14:11-14:18 [test.adb:17:4] |> + references: <| DefiningName "Level_2" test.adb:12:15-12:22 [test.adb:17:4] |> + type: None + expected type: None +Expr: <| Id "Level_2" test.adb:14:11-14:18 [test.adb:17:4] |> + references: <| DefiningName "Level_2" test.adb:12:15-12:22 [test.adb:17:4] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:15:8-15:15 [test.adb:17:4] |> +************************************************************************** + +Expr: <| EndName test.adb:15:8-15:15 [test.adb:17:4] |> + references: + type: None + expected type: None +Expr: <| Id "Level_1" test.adb:15:8-15:15 [test.adb:17:4] |> + references: + type: None + expected type: None + + + +Done. diff --git a/testsuite/tests/name_resolution/attr_function_from_generic/test.yaml b/testsuite/tests/name_resolution/attr_function_from_generic/test.yaml new file mode 100644 index 000000000..e17275cc3 --- /dev/null +++ b/testsuite/tests/name_resolution/attr_function_from_generic/test.yaml @@ -0,0 +1,3 @@ +driver: name-resolution +traverse_generics: true +input_sources: [test.adb] From 323275bd43ba0625b39dbfa7fdd2c9852d119032 Mon Sep 17 00:00:00 2001 From: Romain Beguet Date: Fri, 26 Jan 2024 19:08:51 +0100 Subject: [PATCH 02/11] Shed Entity's rebindings when resolving a generic decl. --- ada/ast.py | 91 +++++++++--- .../test.adb | 32 +++++ .../test.out | 133 ++++++++++++++++++ .../test.yaml | 3 + 4 files changed, 238 insertions(+), 21 deletions(-) create mode 100644 testsuite/tests/name_resolution/nested_instantiation_to_outer_generic/test.adb create mode 100644 testsuite/tests/name_resolution/nested_instantiation_to_outer_generic/test.out create mode 100644 testsuite/tests/name_resolution/nested_instantiation_to_outer_generic/test.yaml diff --git a/ada/ast.py b/ada/ast.py index 467958e2a..2c223a9fd 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -564,6 +564,44 @@ def remove_rebindings(base=T.EnvRebindings, suffix=T.EnvRebindings): base ) + @langkit_property(return_type=T.Bool) + def is_rebound(base=T.EnvRebindings, old_env=T.LexicalEnv): + """ + Return whether ``old_env`` is rebound somewhere inside the given + rebindings. + """ + return And( + Not(base.is_null), + Or(base.old_env == old_env, + Self.is_rebound(base.get_parent, old_env)) + ) + + @langkit_property(return_type=T.EnvRebindings) + def insert_rebindings(base=T.EnvRebindings, to_insert=T.EnvRebindings): + """ + Append rebindings from ``to_insert`` to ``base``, stopping as soon as + an entry from ``to_insert`` is already rebound in ``base``, such that + for example ``insert_rebindings([A, C], [B, C, D]) = [A, C, D]``. + """ + return Cond( + to_insert.is_null, + base, + + base.is_null, + to_insert, + + Self.is_rebound(base, to_insert.old_env), + base, + + Self.insert_rebindings( + base, + to_insert.get_parent + ).append_rebinding( + to_insert.old_env, + to_insert.new_env + ) + ) + # We mark this property as memoizable because for the moment, we only ever # get the first result of logic resolution, so we only ever want the result # of the first evaluation of this property. When we change that, we'll @@ -5101,8 +5139,10 @@ def real_designated_type(typ=T.TypeExpr.entity): node=typ.node, info=T.entity_info.new( md=No(Metadata), - rebindings=typ.info.rebindings - .concat_rebindings(base_rebindings), + rebindings=Self.insert_rebindings( + typ.info.rebindings, + base_rebindings + ), from_rebound=typ.info.from_rebound ) ).designated_type @@ -12251,7 +12291,7 @@ def instantiation_bindings(): # in this non-memoized property to avoid a false "infinite recursion" # property error that can happen when the computation is only done in # instantiation_bindings_internal. - ignore(Var(Self.nonbound_generic_decl)) + ignore(Var(Self.nonbound_generic_decl_from_self)) return Entity.instantiation_bindings_internal @langkit_property(return_type=T.inner_env_assoc.array, memoized=True, @@ -12260,7 +12300,8 @@ def instantiation_bindings_internal(): return If( Entity.is_any_formal, No(T.inner_env_assoc.array), - Self.nonbound_generic_decl._.formal_part.match_param_list( + Self.nonbound_generic_decl_from_self + ._.formal_part.match_param_list( Entity.generic_inst_params, False ).filter( lambda pm: And( @@ -12302,8 +12343,8 @@ def instantiation_bindings_internal(): Entity.generic_inst_params.at(0)._.expr.is_a(T.BoxExpr) ) - nonbound_generic_decl = Property( - Self.as_bare_entity.generic_entity_name + nonbound_generic_decl_from_entity = Property( + Entity.generic_entity_name .all_env_elements_internal( seq=True, seq_from=Self, categories=no_prims ).find( @@ -12315,8 +12356,16 @@ def instantiation_bindings_internal(): lambda _: No(T.GenericDecl.entity) )._.cast(T.GenericDecl), doc=""" - Return the formal package designated by the right hand part of this - generic package instantiation. + Return the generic package designated by the right hand part of this + generic package instantiation as seen from the current generic context. + """ + ) + + nonbound_generic_decl_from_self = Property( + Self.as_bare_entity.nonbound_generic_decl_from_entity, + doc=""" + Return the generic package designated by the right hand part of this + generic package instantiation from a bare generic context. """ ) @@ -12401,7 +12450,7 @@ def parent_instantiation_env(): xref_equation = Property( Bind(Entity.generic_entity_name.ref_var, - Entity.nonbound_generic_decl) + Entity.nonbound_generic_decl_from_self) & Entity.generic_entity_name.match( lambda dn=T.DottedName: dn.prefix.xref_no_overloading, lambda _: LogicTrue() @@ -12557,7 +12606,8 @@ def actual_for_formal(formal_name=T.DefiningName): generic instantiation. Returns null if none is provided, even if there is a default value. """ - return Self.nonbound_generic_decl._.formal_part.match_param_list( + gen_decl = Var(Self.nonbound_generic_decl_from_self) + return gen_decl._.formal_part.match_param_list( Entity.generic_inst_params, False ).find( lambda pm: pm.formal.node == formal_name @@ -12594,15 +12644,15 @@ def designated_subp(): """ Return the subprogram decl designated by this instantiation. """ - return Self.nonbound_generic_decl.then( + return Entity.nonbound_generic_decl_from_entity.then( lambda p: BasicSubpDecl.entity.new( node=p.node.cast(GenericSubpDecl).subp_decl, info=T.entity_info.new( md=Entity.info.md, - rebindings=Entity.info.rebindings - # Append the rebindings from the decl - .concat_rebindings(p._.decl.info.rebindings) - .append_rebinding( + rebindings=Self.insert_rebindings( + p._.decl.info.rebindings, + Entity.info.rebindings + ).append_rebinding( p.node.children_env, Self.instantiation_env ), from_rebound=p.info.from_rebound @@ -12630,18 +12680,17 @@ class GenericPackageInstantiation(GenericInstantiation): @langkit_property() def designated_package(): - return Self.nonbound_generic_decl.then( + return Entity.nonbound_generic_decl_from_entity.then( lambda p: BasePackageDecl.entity.new( node=p.node.cast(GenericPackageDecl).package_decl, info=T.entity_info.new( md=p.info.md, # Take the rebindings from the current context - rebindings=Entity.info.rebindings - - # Append the rebindings from the decl - .concat_rebindings(p._.decl.info.rebindings) - + rebindings=Self.insert_rebindings( + p._.decl.info.rebindings, + Entity.info.rebindings + ) # Append the rebindings for the current instantiation. # NOTE: We use the formal env to create rebindings. There, # we purposefully want the children env of the P node, with diff --git a/testsuite/tests/name_resolution/nested_instantiation_to_outer_generic/test.adb b/testsuite/tests/name_resolution/nested_instantiation_to_outer_generic/test.adb new file mode 100644 index 000000000..71f61d8a7 --- /dev/null +++ b/testsuite/tests/name_resolution/nested_instantiation_to_outer_generic/test.adb @@ -0,0 +1,32 @@ +procedure Test is + generic + package Array_G is + type T is null record; + + generic + procedure Iterate_G (X : T); + end Array_G; + + package body Array_G is + procedure Iterate_G (X : T) is null; + end Array_G; + + package Internal_Address_Set is new Array_G; + + type U is new Internal_Address_Set.T; + + generic + procedure Iterate_G (F : U); + + procedure Iterate_G (F : U) is + procedure Iterate is new Internal_Address_Set.Iterate_G; + begin + Iterate (Internal_Address_Set.T (F)); + end Iterate_G; + + procedure Iterate is new Iterate_G; + pragma Test_Statement; +begin + null; +end Test; + diff --git a/testsuite/tests/name_resolution/nested_instantiation_to_outer_generic/test.out b/testsuite/tests/name_resolution/nested_instantiation_to_outer_generic/test.out new file mode 100644 index 000000000..923e2d936 --- /dev/null +++ b/testsuite/tests/name_resolution/nested_instantiation_to_outer_generic/test.out @@ -0,0 +1,133 @@ +Analyzing test.adb +################## + +Resolving xrefs for node +*********************************************************************************** + +Expr: + references: + type: None + expected type: None +Traversing generic node <| GenericSubpDecl ["Iterate_G"] test.adb:18:4-19:32 [test.adb:27:4] |> +*********************************************************************************************** + +Resolving xrefs for node <| SubpSpec test.adb:19:4-19:31 [test.adb:27:4] |> +*************************************************************************** + + +Resolving xrefs for node <| ParamSpec ["F"] test.adb:19:25-19:30 [test.adb:27:4] |> +*********************************************************************************** + +Expr: <| Id "U" test.adb:19:29-19:30 [test.adb:27:4] |> + references: + type: None + expected type: None + +Traversing generic node <| SubpBody ["Iterate_G"] test.adb:21:4-25:18 [test.adb:27:4] |> +**************************************************************************************** + +Resolving xrefs for node <| SubpSpec test.adb:21:4-21:31 [test.adb:27:4] |> +*************************************************************************** + + +Resolving xrefs for node <| ParamSpec ["F"] test.adb:21:25-21:30 [test.adb:27:4] |> +*********************************************************************************** + +Expr: <| Id "U" test.adb:21:29-21:30 [test.adb:27:4] |> + references: + type: None + expected type: None + +Resolving xrefs for node <| GenericSubpInstantiation ["Iterate"] test.adb:22:7-22:63 [test.adb:27:4] |> +******************************************************************************************************* + +Expr: <| DottedName test.adb:22:32-22:62 [test.adb:27:4] |> + references: <| DefiningName "Iterate_G" test.adb:7:17-7:26 [test.adb:14:4] |> + type: None + expected type: None +Expr: <| Id "Internal_Address_Set" test.adb:22:32-22:52 [test.adb:27:4] |> + references: + type: None + expected type: None +Expr: <| Id "Iterate_G" test.adb:22:53-22:62 [test.adb:27:4] |> + references: <| DefiningName "Iterate_G" test.adb:7:17-7:26 [test.adb:14:4] |> + type: None + expected type: None +Traversing generic node <| GenericSubpDecl ["Iterate_G"] test.adb:6:7-7:35 [test.adb:14:4, test.adb:27:4, test.adb:22:7] |> +*************************************************************************************************************************** + +Resolving xrefs for node <| SubpSpec test.adb:7:7-7:34 [test.adb:14:4, test.adb:27:4, test.adb:22:7] |> +******************************************************************************************************* + + +Resolving xrefs for node <| ParamSpec ["X"] test.adb:7:28-7:33 [test.adb:14:4, test.adb:27:4, test.adb:22:7] |> +*************************************************************************************************************** + +Expr: <| Id "T" test.adb:7:32-7:33 [test.adb:14:4, test.adb:27:4, test.adb:22:7] |> + references: <| DefiningName "T" test.adb:4:12-4:13 [test.adb:14:4] |> + type: None + expected type: None + +Traversing generic node <| NullSubpDecl ["Iterate_G"] test.adb:11:7-11:43 [test.adb:14:4, test.adb:27:4, test.adb:22:7] |> +************************************************************************************************************************** + +Resolving xrefs for node <| SubpSpec test.adb:11:7-11:34 [test.adb:14:4, test.adb:27:4, test.adb:22:7] |> +********************************************************************************************************* + + +Resolving xrefs for node <| ParamSpec ["X"] test.adb:11:28-11:33 [test.adb:14:4, test.adb:27:4, test.adb:22:7] |> +***************************************************************************************************************** + +Expr: <| Id "T" test.adb:11:32-11:33 [test.adb:14:4, test.adb:27:4, test.adb:22:7] |> + references: <| DefiningName "T" test.adb:4:12-4:13 [test.adb:14:4] |> + type: None + expected type: None + + +Resolving xrefs for node <| CallStmt test.adb:24:7-24:44 [test.adb:27:4] |> +*************************************************************************** + +Expr: <| CallExpr test.adb:24:7-24:43 [test.adb:27:4] |> + references: <| DefiningName "Iterate" test.adb:22:17-22:24 [test.adb:27:4] |> + type: None + expected type: None +Expr: <| Id "Iterate" test.adb:24:7-24:14 [test.adb:27:4] |> + references: <| DefiningName "Iterate" test.adb:22:17-22:24 [test.adb:27:4] |> + type: None + expected type: None +Expr: <| CallExpr test.adb:24:16-24:42 [test.adb:27:4] |> + references: <| DefiningName "T" test.adb:4:12-4:13 [test.adb:14:4] |> + type: <| ConcreteTypeDecl ["T"] test.adb:4:7-4:29 [test.adb:14:4] |> + expected type: <| ConcreteTypeDecl ["T"] test.adb:4:7-4:29 [test.adb:14:4] |> +Expr: <| DottedName test.adb:24:16-24:38 [test.adb:27:4] |> + references: <| DefiningName "T" test.adb:4:12-4:13 [test.adb:14:4] |> + type: None + expected type: None +Expr: <| Id "Internal_Address_Set" test.adb:24:16-24:36 [test.adb:27:4] |> + references: + type: None + expected type: None +Expr: <| Id "T" test.adb:24:37-24:38 [test.adb:27:4] |> + references: <| DefiningName "T" test.adb:4:12-4:13 [test.adb:14:4] |> + type: None + expected type: None +Expr: <| Id "F" test.adb:24:40-24:41 [test.adb:27:4] |> + references: <| DefiningName "F" test.adb:21:25-21:26 [test.adb:27:4] |> + type: + expected type: None + +Resolving xrefs for node <| EndName test.adb:25:8-25:17 [test.adb:27:4] |> +************************************************************************** + +Expr: <| EndName test.adb:25:8-25:17 [test.adb:27:4] |> + references: <| DefiningName "Iterate_G" test.adb:21:14-21:23 [test.adb:27:4] |> + type: None + expected type: None +Expr: <| Id "Iterate_G" test.adb:25:8-25:17 [test.adb:27:4] |> + references: <| DefiningName "Iterate_G" test.adb:21:14-21:23 [test.adb:27:4] |> + type: None + expected type: None + + + +Done. diff --git a/testsuite/tests/name_resolution/nested_instantiation_to_outer_generic/test.yaml b/testsuite/tests/name_resolution/nested_instantiation_to_outer_generic/test.yaml new file mode 100644 index 000000000..e17275cc3 --- /dev/null +++ b/testsuite/tests/name_resolution/nested_instantiation_to_outer_generic/test.yaml @@ -0,0 +1,3 @@ +driver: name-resolution +traverse_generics: true +input_sources: [test.adb] From f33a9096c748cc60d1f029290e2cdc5600ff5d94 Mon Sep 17 00:00:00 2001 From: Romain Beguet Date: Tue, 30 Jan 2024 17:35:48 +0100 Subject: [PATCH 03/11] Consider subsets at any level in `unshed_rebindings`. --- ada/ast.py | 21 +- .../unshed_nested_rebindings/test.adb | 47 +++ .../unshed_nested_rebindings/test.out | 362 ++++++++++++++++++ .../unshed_nested_rebindings/test.yaml | 3 + 4 files changed, 428 insertions(+), 5 deletions(-) create mode 100644 testsuite/tests/name_resolution/unshed_nested_rebindings/test.adb create mode 100644 testsuite/tests/name_resolution/unshed_nested_rebindings/test.out create mode 100644 testsuite/tests/name_resolution/unshed_nested_rebindings/test.yaml diff --git a/ada/ast.py b/ada/ast.py index 2c223a9fd..940fac106 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -602,6 +602,21 @@ def insert_rebindings(base=T.EnvRebindings, to_insert=T.EnvRebindings): ) ) + @langkit_property(return_type=T.Bool) + def has_parent_rebindings(base=T.EnvRebindings, parent=T.EnvRebindings): + """ + Return whether ``parent`` is a parent of ``base``. This considers + the chain as a whole, i.e. ``has_parent_rebindings([A, B, C], [A, B])`` + returns True, but both ``has_parent_rebindings([A, B, C], [B, C])`` as + well as ``has_parent_rebindings([A, C], [A, B])`` return False. + """ + return Or( + base == parent, + parent.is_null, + Not(base.is_null) + & Self.has_parent_rebindings(base.get_parent, parent) + ) + # We mark this property as memoizable because for the moment, we only ever # get the first result of logic resolution, so we only ever want the result # of the first evaluation of this property. When we change that, we'll @@ -2734,11 +2749,7 @@ def unshed_rebindings_helper(rebindings=T.EnvRebindings): Entity.info.rebindings == rebindings, Entity, - Or( - Entity.info.rebindings == No(T.EnvRebindings), - rebindings.get_parent == Entity.info.rebindings, - ), - + Self.has_parent_rebindings(rebindings, Entity.info.rebindings), BasicDecl.entity.new( node=Self, info=T.entity_info.new( diff --git a/testsuite/tests/name_resolution/unshed_nested_rebindings/test.adb b/testsuite/tests/name_resolution/unshed_nested_rebindings/test.adb new file mode 100644 index 000000000..efb96cefd --- /dev/null +++ b/testsuite/tests/name_resolution/unshed_nested_rebindings/test.adb @@ -0,0 +1,47 @@ +procedure Test is + generic + package Data_G is + generic + package Buffer_G is + procedure Test; + end Buffer_G; + end Data_G; + + package body Data_G is + package body Buffer_G is + X : Integer := 0; + + procedure Test is + begin + Buffer_G.X := Buffer_G.X + 1; + end Test; + end Buffer_G; + end Data_G; + + generic + with package Data is new Data_G (<>); + package Table_G is + procedure Test; + end Table_G; + + package body Table_G is + package Buffer is new Data.Buffer_G; + + procedure Test is + begin + Buffer.Test; + end Test; + end Table_G; + + generic + with package Table is new Table_G (<>); + package Action_G is + end Action_G; + + package My_Data is new Data_G; + package My_Table is new Table_G (My_Data); + package My_Action is new Action_G (My_Table); + pragma Test_Statement; +begin + null; +end Test; diff --git a/testsuite/tests/name_resolution/unshed_nested_rebindings/test.out b/testsuite/tests/name_resolution/unshed_nested_rebindings/test.out new file mode 100644 index 000000000..654d3d913 --- /dev/null +++ b/testsuite/tests/name_resolution/unshed_nested_rebindings/test.out @@ -0,0 +1,362 @@ +Analyzing test.adb +################## + +Resolving xrefs for node +**************************************************************************************** + +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Traversing generic node <| GenericPackageDecl ["Action_G"] test.adb:36:4-39:17 [test.adb:43:4] |> +************************************************************************************************* + +Resolving xrefs for node <| GenericPackageInstantiation ["Table"] test.adb:37:12-37:46 [test.adb:43:4] |> +********************************************************************************************************* + +Expr: <| Id "Table_G" test.adb:37:33-37:40 [test.adb:43:4] |> + references: + type: None + expected type: None +Expr: <| BoxExpr test.adb:37:42-37:44 [test.adb:43:4] |> + type: None + expected type: None +Traversing generic node <| GenericPackageDecl ["Table_G"] test.adb:21:4-25:16 [test.adb:42:4] |> +************************************************************************************************ + +Resolving xrefs for node <| GenericPackageInstantiation ["Data"] test.adb:22:12-22:44 [test.adb:42:4] |> +******************************************************************************************************** + +Expr: <| Id "Data_G" test.adb:22:32-22:38 [test.adb:42:4] |> + references: + type: None + expected type: None +Expr: <| BoxExpr test.adb:22:40-22:42 [test.adb:42:4] |> + type: None + expected type: None +Traversing generic node <| GenericPackageDecl ["Data_G"] test.adb:2:4-8:15 [test.adb:41:4] |> +********************************************************************************************* + +Resolving xrefs for node <| SubpSpec test.adb:6:10-6:24 [test.adb:41:4] |> +************************************************************************** + + +Resolving xrefs for node <| EndName test.adb:7:11-7:19 [test.adb:41:4] |> +************************************************************************* + +Expr: <| EndName test.adb:7:11-7:19 [test.adb:41:4] |> + references: <| DefiningName "Buffer_G" test.adb:5:15-5:23 [test.adb:41:4] |> + type: None + expected type: None +Expr: <| Id "Buffer_G" test.adb:7:11-7:19 [test.adb:41:4] |> + references: <| DefiningName "Buffer_G" test.adb:5:15-5:23 [test.adb:41:4] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:8:8-8:14 [test.adb:41:4] |> +************************************************************************ + +Expr: <| EndName test.adb:8:8-8:14 [test.adb:41:4] |> + references: + type: None + expected type: None +Expr: <| Id "Data_G" test.adb:8:8-8:14 [test.adb:41:4] |> + references: + type: None + expected type: None + +Traversing generic node <| PackageBody ["Data_G"] test.adb:10:4-19:15 [test.adb:41:4] |> +**************************************************************************************** + +Resolving xrefs for node <| ObjectDecl ["X"] test.adb:12:10-12:27 [test.adb:41:4] |> +************************************************************************************ + +Expr: <| Id "Integer" test.adb:12:14-12:21 [test.adb:41:4] |> + references: + type: None + expected type: None +Expr: <| Int test.adb:12:25-12:26 [test.adb:41:4] |> + references: None + type: + expected type: + +Resolving xrefs for node <| SubpSpec test.adb:14:10-14:24 [test.adb:41:4] |> +**************************************************************************** + + +Resolving xrefs for node <| AssignStmt test.adb:16:13-16:42 [test.adb:41:4] |> +****************************************************************************** + +Expr: <| DottedName test.adb:16:13-16:23 [test.adb:41:4] |> + references: <| DefiningName "X" test.adb:12:10-12:11 [test.adb:41:4] |> + type: + expected type: None +Expr: <| Id "Buffer_G" test.adb:16:13-16:21 [test.adb:41:4] |> + references: <| DefiningName "Buffer_G" test.adb:5:15-5:23 [test.adb:41:4] |> + type: None + expected type: None +Expr: <| Id "X" test.adb:16:22-16:23 [test.adb:41:4] |> + references: <| DefiningName "X" test.adb:12:10-12:11 [test.adb:41:4] |> + type: + expected type: None +Expr: <| BinOp test.adb:16:27-16:41 [test.adb:41:4] |> + type: + expected type: +Expr: <| DottedName test.adb:16:27-16:37 [test.adb:41:4] |> + references: <| DefiningName "X" test.adb:12:10-12:11 [test.adb:41:4] |> + type: + expected type: +Expr: <| Id "Buffer_G" test.adb:16:27-16:35 [test.adb:41:4] |> + references: <| DefiningName "Buffer_G" test.adb:5:15-5:23 [test.adb:41:4] |> + type: None + expected type: None +Expr: <| Id "X" test.adb:16:36-16:37 [test.adb:41:4] |> + references: <| DefiningName "X" test.adb:12:10-12:11 [test.adb:41:4] |> + type: + expected type: +Expr: <| OpPlus "+" test.adb:16:38-16:39 [test.adb:41:4] |> + references: None + type: None + expected type: None +Expr: <| Int test.adb:16:40-16:41 [test.adb:41:4] |> + references: None + type: + expected type: + +Resolving xrefs for node <| EndName test.adb:17:14-17:18 [test.adb:41:4] |> +*************************************************************************** + +Expr: <| EndName test.adb:17:14-17:18 [test.adb:41:4] |> + references: <| DefiningName "Test" test.adb:14:20-14:24 [test.adb:41:4] |> + type: None + expected type: None +Expr: <| Id "Test" test.adb:17:14-17:18 [test.adb:41:4] |> + references: <| DefiningName "Test" test.adb:14:20-14:24 [test.adb:41:4] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:18:11-18:19 [test.adb:41:4] |> +*************************************************************************** + +Expr: <| EndName test.adb:18:11-18:19 [test.adb:41:4] |> + references: <| DefiningName "Buffer_G" test.adb:11:20-11:28 [test.adb:41:4] |> + type: None + expected type: None +Expr: <| Id "Buffer_G" test.adb:18:11-18:19 [test.adb:41:4] |> + references: <| DefiningName "Buffer_G" test.adb:11:20-11:28 [test.adb:41:4] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:19:8-19:14 [test.adb:41:4] |> +************************************************************************** + +Expr: <| EndName test.adb:19:8-19:14 [test.adb:41:4] |> + references: <| DefiningName "Data_G" test.adb:10:17-10:23 [test.adb:41:4] |> + type: None + expected type: None +Expr: <| Id "Data_G" test.adb:19:8-19:14 [test.adb:41:4] |> + references: <| DefiningName "Data_G" test.adb:10:17-10:23 [test.adb:41:4] |> + type: None + expected type: None + + +Resolving xrefs for node <| SubpSpec test.adb:24:7-24:21 [test.adb:42:4] |> +*************************************************************************** + + +Resolving xrefs for node <| EndName test.adb:25:8-25:15 [test.adb:42:4] |> +************************************************************************** + +Expr: <| EndName test.adb:25:8-25:15 [test.adb:42:4] |> + references: + type: None + expected type: None +Expr: <| Id "Table_G" test.adb:25:8-25:15 [test.adb:42:4] |> + references: + type: None + expected type: None + +Traversing generic node <| PackageBody ["Table_G"] test.adb:27:4-34:16 [test.adb:42:4] |> +***************************************************************************************** + +Resolving xrefs for node <| GenericPackageInstantiation ["Buffer"] test.adb:28:7-28:43 [test.adb:42:4] |> +********************************************************************************************************* + +Expr: <| DottedName test.adb:28:29-28:42 [test.adb:42:4] |> + references: <| DefiningName "Buffer_G" test.adb:5:15-5:23 [test.adb:22:12] |> + type: None + expected type: None +Expr: <| Id "Data" test.adb:28:29-28:33 [test.adb:42:4] |> + references: + type: None + expected type: None +Expr: <| Id "Buffer_G" test.adb:28:34-28:42 [test.adb:42:4] |> + references: <| DefiningName "Buffer_G" test.adb:5:15-5:23 [test.adb:22:12] |> + type: None + expected type: None +Traversing generic node <| GenericPackageDecl ["Buffer_G"] test.adb:4:7-7:20 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> +***************************************************************************************************************************** + +Resolving xrefs for node <| SubpSpec test.adb:6:10-6:24 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> +******************************************************************************************************** + + +Resolving xrefs for node <| EndName test.adb:7:11-7:19 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> +******************************************************************************************************* + +Expr: <| EndName test.adb:7:11-7:19 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + references: <| DefiningName "Buffer" test.adb:28:15-28:21 [test.adb:41:4, test.adb:42:4] |> + type: None + expected type: None +Expr: <| Id "Buffer_G" test.adb:7:11-7:19 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + references: <| DefiningName "Buffer" test.adb:28:15-28:21 [test.adb:41:4, test.adb:42:4] |> + type: None + expected type: None + +Traversing generic node <| PackageBody ["Buffer_G"] test.adb:11:7-18:20 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> +************************************************************************************************************************ + +Resolving xrefs for node <| ObjectDecl ["X"] test.adb:12:10-12:27 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> +****************************************************************************************************************** + +Expr: <| Id "Integer" test.adb:12:14-12:21 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + references: + type: None + expected type: None +Expr: <| Int test.adb:12:25-12:26 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + references: None + type: + expected type: + +Resolving xrefs for node <| SubpSpec test.adb:14:10-14:24 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> +********************************************************************************************************** + + +Resolving xrefs for node <| AssignStmt test.adb:16:13-16:42 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> +************************************************************************************************************ + +Expr: <| DottedName test.adb:16:13-16:23 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + references: <| DefiningName "X" test.adb:12:10-12:11 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + type: + expected type: None +Expr: <| Id "Buffer_G" test.adb:16:13-16:21 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + references: <| DefiningName "Buffer_G" test.adb:5:15-5:23 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + type: None + expected type: None +Expr: <| Id "X" test.adb:16:22-16:23 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + references: <| DefiningName "X" test.adb:12:10-12:11 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + type: + expected type: None +Expr: <| BinOp test.adb:16:27-16:41 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + type: + expected type: +Expr: <| DottedName test.adb:16:27-16:37 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + references: <| DefiningName "X" test.adb:12:10-12:11 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + type: + expected type: +Expr: <| Id "Buffer_G" test.adb:16:27-16:35 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + references: <| DefiningName "Buffer_G" test.adb:5:15-5:23 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + type: None + expected type: None +Expr: <| Id "X" test.adb:16:36-16:37 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + references: <| DefiningName "X" test.adb:12:10-12:11 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + type: + expected type: +Expr: <| OpPlus "+" test.adb:16:38-16:39 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + references: None + type: None + expected type: None +Expr: <| Int test.adb:16:40-16:41 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + references: None + type: + expected type: + +Resolving xrefs for node <| EndName test.adb:17:14-17:18 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> +********************************************************************************************************* + +Expr: <| EndName test.adb:17:14-17:18 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + references: <| DefiningName "Test" test.adb:14:20-14:24 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + type: None + expected type: None +Expr: <| Id "Test" test.adb:17:14-17:18 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + references: <| DefiningName "Test" test.adb:14:20-14:24 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:18:11-18:19 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> +********************************************************************************************************* + +Expr: <| EndName test.adb:18:11-18:19 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + references: <| DefiningName "Buffer_G" test.adb:11:20-11:28 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + type: None + expected type: None +Expr: <| Id "Buffer_G" test.adb:18:11-18:19 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + references: <| DefiningName "Buffer_G" test.adb:11:20-11:28 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + type: None + expected type: None + + +Resolving xrefs for node <| SubpSpec test.adb:30:7-30:21 [test.adb:42:4] |> +*************************************************************************** + + +Resolving xrefs for node <| CallStmt test.adb:32:10-32:22 [test.adb:42:4] |> +**************************************************************************** + +Expr: <| DottedName test.adb:32:10-32:21 [test.adb:42:4] |> + references: <| DefiningName "Test" test.adb:6:20-6:24 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + type: None + expected type: None +Expr: <| Id "Buffer" test.adb:32:10-32:16 [test.adb:42:4] |> + references: <| DefiningName "Buffer" test.adb:28:15-28:21 [test.adb:42:4] |> + type: None + expected type: None +Expr: <| Id "Test" test.adb:32:17-32:21 [test.adb:42:4] |> + references: <| DefiningName "Test" test.adb:6:20-6:24 [test.adb:41:4, test.adb:42:4, test.adb:28:7] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:33:11-33:15 [test.adb:42:4] |> +*************************************************************************** + +Expr: <| EndName test.adb:33:11-33:15 [test.adb:42:4] |> + references: <| DefiningName "Test" test.adb:30:17-30:21 [test.adb:42:4] |> + type: None + expected type: None +Expr: <| Id "Test" test.adb:33:11-33:15 [test.adb:42:4] |> + references: <| DefiningName "Test" test.adb:30:17-30:21 [test.adb:42:4] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:34:8-34:15 [test.adb:42:4] |> +************************************************************************** + +Expr: <| EndName test.adb:34:8-34:15 [test.adb:42:4] |> + references: <| DefiningName "Table_G" test.adb:27:17-27:24 [test.adb:42:4] |> + type: None + expected type: None +Expr: <| Id "Table_G" test.adb:34:8-34:15 [test.adb:42:4] |> + references: <| DefiningName "Table_G" test.adb:27:17-27:24 [test.adb:42:4] |> + type: None + expected type: None + + +Resolving xrefs for node <| EndName test.adb:39:8-39:16 [test.adb:43:4] |> +************************************************************************** + +Expr: <| EndName test.adb:39:8-39:16 [test.adb:43:4] |> + references: + type: None + expected type: None +Expr: <| Id "Action_G" test.adb:39:8-39:16 [test.adb:43:4] |> + references: + type: None + expected type: None + + + +Done. diff --git a/testsuite/tests/name_resolution/unshed_nested_rebindings/test.yaml b/testsuite/tests/name_resolution/unshed_nested_rebindings/test.yaml new file mode 100644 index 000000000..e17275cc3 --- /dev/null +++ b/testsuite/tests/name_resolution/unshed_nested_rebindings/test.yaml @@ -0,0 +1,3 @@ +driver: name-resolution +traverse_generics: true +input_sources: [test.adb] From 90c4cabde2d02ab0cef77b2af72c75e19939c61f Mon Sep 17 00:00:00 2001 From: Romain Beguet Date: Wed, 31 Jan 2024 10:17:09 +0100 Subject: [PATCH 04/11] Fix fully qualified lookups from instantiated contexts. --- ada/ast.py | 13 +- .../formal-child.adb | 9 + .../formal-child.ads | 4 + .../qualified_lookup_from_generic/formal.adb | 9 + .../qualified_lookup_from_generic/formal.ads | 6 + .../qualified_lookup_from_generic/test.adb | 26 ++ .../qualified_lookup_from_generic/test.out | 295 ++++++++++++++++++ .../qualified_lookup_from_generic/test.yaml | 3 + 8 files changed, 362 insertions(+), 3 deletions(-) create mode 100644 testsuite/tests/name_resolution/qualified_lookup_from_generic/formal-child.adb create mode 100644 testsuite/tests/name_resolution/qualified_lookup_from_generic/formal-child.ads create mode 100644 testsuite/tests/name_resolution/qualified_lookup_from_generic/formal.adb create mode 100644 testsuite/tests/name_resolution/qualified_lookup_from_generic/formal.ads create mode 100644 testsuite/tests/name_resolution/qualified_lookup_from_generic/test.adb create mode 100644 testsuite/tests/name_resolution/qualified_lookup_from_generic/test.out create mode 100644 testsuite/tests/name_resolution/qualified_lookup_from_generic/test.yaml diff --git a/ada/ast.py b/ada/ast.py index 940fac106..2fc2c02a9 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -18956,11 +18956,16 @@ def pkg_env(from_pkg=T.BasicDecl.entity): )) return Cond( - # If we're looking from the body, return a group of all the # relevant envs together. Not(package_body_env.equals(EmptyEnv)) - & Self.is_children_env(package_body_env, + # Since origin or Self do not carry rebindings, `is_children_env` + # would always return False in instantiated generics (since + # `package_body_env` is a rebound environment). Fortunately, these + # visibility rules are not instantiation-dependent, so we can use + # `.env_node.children_env` on `package_body_env` to do the check on + # the bare non-rebound lexical envs. + & Self.is_children_env(package_body_env.env_node._.children_env, (origin._or(Self)).node_env), Array([ package_body_env, private_part_env, env, formals_env @@ -18968,7 +18973,9 @@ def pkg_env(from_pkg=T.BasicDecl.entity): # If we're looking from the private part, return a group of private # part + public part. - Self.is_children_env(private_part_env, + # See corresponding comment on `package_body_env` to understand why + # we use `.env_node.children_env`. + Self.is_children_env(private_part_env.env_node._.children_env, (origin._or(Self)).node_env), Array([private_part_env, env, formals_env]).env_group(), diff --git a/testsuite/tests/name_resolution/qualified_lookup_from_generic/formal-child.adb b/testsuite/tests/name_resolution/qualified_lookup_from_generic/formal-child.adb new file mode 100644 index 000000000..a5cf0629a --- /dev/null +++ b/testsuite/tests/name_resolution/qualified_lookup_from_generic/formal-child.adb @@ -0,0 +1,9 @@ +package body Formal.Child is + X : Integer; + + procedure Bar is + begin + Child.X := 42; + end Bar; +end Formal.Child; + diff --git a/testsuite/tests/name_resolution/qualified_lookup_from_generic/formal-child.ads b/testsuite/tests/name_resolution/qualified_lookup_from_generic/formal-child.ads new file mode 100644 index 000000000..ac37b61d1 --- /dev/null +++ b/testsuite/tests/name_resolution/qualified_lookup_from_generic/formal-child.ads @@ -0,0 +1,4 @@ +generic +package Formal.Child is + procedure Bar; +end Formal.Child; diff --git a/testsuite/tests/name_resolution/qualified_lookup_from_generic/formal.adb b/testsuite/tests/name_resolution/qualified_lookup_from_generic/formal.adb new file mode 100644 index 000000000..bf682dee7 --- /dev/null +++ b/testsuite/tests/name_resolution/qualified_lookup_from_generic/formal.adb @@ -0,0 +1,9 @@ +package body Formal is + X : Integer; + + procedure Baz is + begin + Formal.X := 42; + end Baz; +end Formal; + diff --git a/testsuite/tests/name_resolution/qualified_lookup_from_generic/formal.ads b/testsuite/tests/name_resolution/qualified_lookup_from_generic/formal.ads new file mode 100644 index 000000000..2f062d4e0 --- /dev/null +++ b/testsuite/tests/name_resolution/qualified_lookup_from_generic/formal.ads @@ -0,0 +1,6 @@ +generic +package Formal is + procedure Baz; +private +end Formal; + diff --git a/testsuite/tests/name_resolution/qualified_lookup_from_generic/test.adb b/testsuite/tests/name_resolution/qualified_lookup_from_generic/test.adb new file mode 100644 index 000000000..579f45503 --- /dev/null +++ b/testsuite/tests/name_resolution/qualified_lookup_from_generic/test.adb @@ -0,0 +1,26 @@ +with Formal; +with Formal.Child; + +procedure Test is + generic + with package Act is new Formal; + package Gen is + procedure Foo; + end Gen; + + package body Gen is + package Child_Act is new Act.Child; + + procedure Foo is + begin + Child_Act.Bar; + end Foo; + end Gen; + + package Package_Actual is new Formal; + + package Inst is new Gen (Package_Actual); + pragma Test_Statement; +begin + null; +end Test; diff --git a/testsuite/tests/name_resolution/qualified_lookup_from_generic/test.out b/testsuite/tests/name_resolution/qualified_lookup_from_generic/test.out new file mode 100644 index 000000000..ba5701d1e --- /dev/null +++ b/testsuite/tests/name_resolution/qualified_lookup_from_generic/test.out @@ -0,0 +1,295 @@ +Analyzing test.adb +################## + +Resolving xrefs for node +*********************************************************************************** + +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Traversing generic node <| GenericPackageDecl ["Gen"] test.adb:5:4-9:12 [test.adb:22:4] |> +****************************************************************************************** + +Resolving xrefs for node <| GenericPackageInstantiation ["Act"] test.adb:6:12-6:38 [test.adb:22:4] |> +***************************************************************************************************** + +Expr: <| Id "Formal" test.adb:6:31-6:37 [test.adb:22:4] |> + references: + type: None + expected type: None +Traversing generic node <| GenericPackageDecl ["Formal"] formal.ads:1:1-5:12 [test.adb:20:4] |> +*********************************************************************************************** + +Resolving xrefs for node <| SubpSpec formal.ads:3:4-3:17 [test.adb:20:4] |> +*************************************************************************** + + +Resolving xrefs for node <| EndName formal.ads:5:5-5:11 [test.adb:20:4] |> +************************************************************************** + +Expr: <| EndName formal.ads:5:5-5:11 [test.adb:20:4] |> + references: + type: None + expected type: None +Expr: <| Id "Formal" formal.ads:5:5-5:11 [test.adb:20:4] |> + references: + type: None + expected type: None + +Traversing generic node <| PackageBody ["Formal"] formal.adb:1:1-8:12 [test.adb:20:4] |> +**************************************************************************************** + +Resolving xrefs for node <| ObjectDecl ["X"] formal.adb:2:4-2:16 [test.adb:20:4] |> +*********************************************************************************** + +Expr: <| Id "Integer" formal.adb:2:8-2:15 [test.adb:20:4] |> + references: + type: None + expected type: None + +Resolving xrefs for node <| SubpSpec formal.adb:4:4-4:17 [test.adb:20:4] |> +*************************************************************************** + + +Resolving xrefs for node <| AssignStmt formal.adb:6:7-6:22 [test.adb:20:4] |> +***************************************************************************** + +Expr: <| DottedName formal.adb:6:7-6:15 [test.adb:20:4] |> + references: <| DefiningName "X" formal.adb:2:4-2:5 [test.adb:20:4] |> + type: + expected type: None +Expr: <| Id "Formal" formal.adb:6:7-6:13 [test.adb:20:4] |> + references: <| DefiningName "Formal" formal.ads:2:9-2:15 [test.adb:20:4] |> + type: None + expected type: None +Expr: <| Id "X" formal.adb:6:14-6:15 [test.adb:20:4] |> + references: <| DefiningName "X" formal.adb:2:4-2:5 [test.adb:20:4] |> + type: + expected type: None +Expr: <| Int formal.adb:6:19-6:21 [test.adb:20:4] |> + references: None + type: + expected type: + +Resolving xrefs for node <| EndName formal.adb:7:8-7:11 [test.adb:20:4] |> +************************************************************************** + +Expr: <| EndName formal.adb:7:8-7:11 [test.adb:20:4] |> + references: <| DefiningName "Baz" formal.adb:4:14-4:17 [test.adb:20:4] |> + type: None + expected type: None +Expr: <| Id "Baz" formal.adb:7:8-7:11 [test.adb:20:4] |> + references: <| DefiningName "Baz" formal.adb:4:14-4:17 [test.adb:20:4] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName formal.adb:8:5-8:11 [test.adb:20:4] |> +************************************************************************** + +Expr: <| EndName formal.adb:8:5-8:11 [test.adb:20:4] |> + references: <| DefiningName "Formal" formal.adb:1:14-1:20 [test.adb:20:4] |> + type: None + expected type: None +Expr: <| Id "Formal" formal.adb:8:5-8:11 [test.adb:20:4] |> + references: <| DefiningName "Formal" formal.adb:1:14-1:20 [test.adb:20:4] |> + type: None + expected type: None + + +Resolving xrefs for node <| SubpSpec test.adb:8:7-8:20 [test.adb:22:4] |> +************************************************************************* + + +Resolving xrefs for node <| EndName test.adb:9:8-9:11 [test.adb:22:4] |> +************************************************************************ + +Expr: <| EndName test.adb:9:8-9:11 [test.adb:22:4] |> + references: + type: None + expected type: None +Expr: <| Id "Gen" test.adb:9:8-9:11 [test.adb:22:4] |> + references: + type: None + expected type: None + +Traversing generic node <| PackageBody ["Gen"] test.adb:11:4-18:12 [test.adb:22:4] |> +************************************************************************************* + +Resolving xrefs for node <| GenericPackageInstantiation ["Child_Act"] test.adb:12:7-12:42 [test.adb:22:4] |> +************************************************************************************************************ + +Expr: <| DottedName test.adb:12:32-12:41 [test.adb:22:4] |> + references: <| DefiningName "Formal.Child" formal-child.ads:2:9-2:21 [test.adb:6:12] |> + type: None + expected type: None +Expr: <| Id "Act" test.adb:12:32-12:35 [test.adb:22:4] |> + references: + type: None + expected type: None +Expr: <| Id "Child" test.adb:12:36-12:41 [test.adb:22:4] |> + references: <| DefiningName "Formal.Child" formal-child.ads:2:9-2:21 [test.adb:6:12] |> + type: None + expected type: None +Traversing generic node <| GenericPackageDecl ["Formal.Child"] formal-child.ads:1:1-4:18 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> +***************************************************************************************************************************************** + +Resolving xrefs for node <| DefiningName "Formal.Child" formal-child.ads:2:9-2:21 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> +********************************************************************************************************************************** + +Expr: <| Id "Formal" formal-child.ads:2:9-2:15 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: + type: None + expected type: None + +Resolving xrefs for node <| SubpSpec formal-child.ads:3:4-3:17 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> +*************************************************************************************************************** + + +Resolving xrefs for node <| EndName formal-child.ads:4:5-4:17 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> +************************************************************************************************************** + +Expr: <| EndName formal-child.ads:4:5-4:17 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: <| DefiningName "Child_Act" test.adb:12:15-12:24 [test.adb:20:4, test.adb:22:4] |> + type: None + expected type: None +Expr: <| DottedName formal-child.ads:4:5-4:17 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: <| DefiningName "Child_Act" test.adb:12:15-12:24 [test.adb:20:4, test.adb:22:4] |> + type: None + expected type: None +Expr: <| Id "Formal" formal-child.ads:4:5-4:11 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: + type: None + expected type: None +Expr: <| Id "Child" formal-child.ads:4:12-4:17 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: <| DefiningName "Child_Act" test.adb:12:15-12:24 [test.adb:20:4, test.adb:22:4] |> + type: None + expected type: None + +Traversing generic node <| PackageBody ["Formal.Child"] formal-child.adb:1:1-8:18 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> +********************************************************************************************************************************** + +Resolving xrefs for node <| DefiningName "Formal.Child" formal-child.adb:1:14-1:26 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> +*********************************************************************************************************************************** + +Expr: <| Id "Formal" formal-child.adb:1:14-1:20 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: + type: None + expected type: None + +Resolving xrefs for node <| ObjectDecl ["X"] formal-child.adb:2:4-2:16 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> +*********************************************************************************************************************** + +Expr: <| Id "Integer" formal-child.adb:2:8-2:15 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: + type: None + expected type: None + +Resolving xrefs for node <| SubpSpec formal-child.adb:4:4-4:17 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> +*************************************************************************************************************** + + +Resolving xrefs for node <| AssignStmt formal-child.adb:6:7-6:21 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> +***************************************************************************************************************** + +Expr: <| DottedName formal-child.adb:6:7-6:14 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: <| DefiningName "X" formal-child.adb:2:4-2:5 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + type: + expected type: None +Expr: <| Id "Child" formal-child.adb:6:7-6:12 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: <| DefiningName "Formal.Child" formal-child.ads:2:9-2:21 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + type: None + expected type: None +Expr: <| Id "X" formal-child.adb:6:13-6:14 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: <| DefiningName "X" formal-child.adb:2:4-2:5 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + type: + expected type: None +Expr: <| Int formal-child.adb:6:18-6:20 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: None + type: + expected type: + +Resolving xrefs for node <| EndName formal-child.adb:7:8-7:11 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> +************************************************************************************************************** + +Expr: <| EndName formal-child.adb:7:8-7:11 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: <| DefiningName "Bar" formal-child.adb:4:14-4:17 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + type: None + expected type: None +Expr: <| Id "Bar" formal-child.adb:7:8-7:11 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: <| DefiningName "Bar" formal-child.adb:4:14-4:17 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName formal-child.adb:8:5-8:17 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> +************************************************************************************************************** + +Expr: <| EndName formal-child.adb:8:5-8:17 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: <| DefiningName "Formal.Child" formal-child.adb:1:14-1:26 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + type: None + expected type: None +Expr: <| DottedName formal-child.adb:8:5-8:17 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: <| DefiningName "Formal.Child" formal-child.adb:1:14-1:26 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + type: None + expected type: None +Expr: <| Id "Formal" formal-child.adb:8:5-8:11 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: + type: None + expected type: None +Expr: <| Id "Child" formal-child.adb:8:12-8:17 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + references: <| DefiningName "Formal.Child" formal-child.adb:1:14-1:26 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + type: None + expected type: None + + +Resolving xrefs for node <| SubpSpec test.adb:14:7-14:20 [test.adb:22:4] |> +*************************************************************************** + + +Resolving xrefs for node <| CallStmt test.adb:16:10-16:24 [test.adb:22:4] |> +**************************************************************************** + +Expr: <| DottedName test.adb:16:10-16:23 [test.adb:22:4] |> + references: <| DefiningName "Bar" formal-child.ads:3:14-3:17 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + type: None + expected type: None +Expr: <| Id "Child_Act" test.adb:16:10-16:19 [test.adb:22:4] |> + references: <| DefiningName "Child_Act" test.adb:12:15-12:24 [test.adb:22:4] |> + type: None + expected type: None +Expr: <| Id "Bar" test.adb:16:20-16:23 [test.adb:22:4] |> + references: <| DefiningName "Bar" formal-child.ads:3:14-3:17 [test.adb:20:4, test.adb:22:4, test.adb:12:7] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:17:11-17:14 [test.adb:22:4] |> +*************************************************************************** + +Expr: <| EndName test.adb:17:11-17:14 [test.adb:22:4] |> + references: <| DefiningName "Foo" test.adb:14:17-14:20 [test.adb:22:4] |> + type: None + expected type: None +Expr: <| Id "Foo" test.adb:17:11-17:14 [test.adb:22:4] |> + references: <| DefiningName "Foo" test.adb:14:17-14:20 [test.adb:22:4] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:18:8-18:11 [test.adb:22:4] |> +************************************************************************** + +Expr: <| EndName test.adb:18:8-18:11 [test.adb:22:4] |> + references: <| DefiningName "Gen" test.adb:11:17-11:20 [test.adb:22:4] |> + type: None + expected type: None +Expr: <| Id "Gen" test.adb:18:8-18:11 [test.adb:22:4] |> + references: <| DefiningName "Gen" test.adb:11:17-11:20 [test.adb:22:4] |> + type: None + expected type: None + + + +Done. diff --git a/testsuite/tests/name_resolution/qualified_lookup_from_generic/test.yaml b/testsuite/tests/name_resolution/qualified_lookup_from_generic/test.yaml new file mode 100644 index 000000000..e17275cc3 --- /dev/null +++ b/testsuite/tests/name_resolution/qualified_lookup_from_generic/test.yaml @@ -0,0 +1,3 @@ +driver: name-resolution +traverse_generics: true +input_sources: [test.adb] From d027e456fa3a133f08383ef2ec3c3413e3638c72 Mon Sep 17 00:00:00 2001 From: Romain Beguet Date: Wed, 31 Jan 2024 12:28:50 +0100 Subject: [PATCH 05/11] Handle traversal of formal packages. When navigating inside a formal package, resolving a formal parameter won't necessarily return a concrete entity, as a box expr (<>) may have been used in place of the formal parameter. So, return `None` for those cases. --- ada/ast.py | 21 +++-- .../traverse_formal_package/test.adb | 22 +++++ .../traverse_formal_package/test.out | 85 +++++++++++++++++++ .../traverse_formal_package/test.yaml | 3 + 4 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 testsuite/tests/name_resolution/traverse_formal_package/test.adb create mode 100644 testsuite/tests/name_resolution/traverse_formal_package/test.out create mode 100644 testsuite/tests/name_resolution/traverse_formal_package/test.yaml diff --git a/ada/ast.py b/ada/ast.py index 2fc2c02a9..adf5a1351 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -13035,14 +13035,25 @@ def resolve_actual_name(name=T.Expr.entity): Note that we cannot simply call ``referenced_decl`` here as this would cause name resolution recursions which we want to avoid at all cost. """ - return origin.bind(name.node, name.cast(AttributeRef).then( - lambda attr: attr.attribute_subprogram, - default_val=name.cast(Name).all_env_elements.find( + return origin.bind(name.node, Cond( + name.is_a(AttributeRef), + name.cast(AttributeRef).attribute_subprogram, + + name.is_a(BoxExpr), + # We are inside an instantiation of formal package without + # constraint on this function (so, a BoxExpr). + No(BasicDecl.entity), + + name.is_a(Name), + name.cast(Name).all_env_elements.find( lambda el: el.cast(BasicDecl)._.subp_decl_match_signature( Entity ) - ) - )).cast(BasicDecl) + ).cast(BasicDecl), + + PropertyError(BasicDecl.entity, + "invalid actual for subprogram formal") + )) @langkit_property(return_type=T.BasicDecl.entity) def corresponding_actual_impl(rb=T.EnvRebindings): diff --git a/testsuite/tests/name_resolution/traverse_formal_package/test.adb b/testsuite/tests/name_resolution/traverse_formal_package/test.adb new file mode 100644 index 000000000..8f079422c --- /dev/null +++ b/testsuite/tests/name_resolution/traverse_formal_package/test.adb @@ -0,0 +1,22 @@ +procedure Test is + generic + with procedure Foo is <>; + package Formal_G is + procedure Bar; + end Formal_G; + + package body Formal_G is + procedure Bar is + begin + Foo; + end Bar; + end Formal_G; + + generic + with package Formal is new Formal_G (<>); + pragma Test_Block; + package Gen is + end Gen; +begin + null; +end Test; diff --git a/testsuite/tests/name_resolution/traverse_formal_package/test.out b/testsuite/tests/name_resolution/traverse_formal_package/test.out new file mode 100644 index 000000000..01deaac01 --- /dev/null +++ b/testsuite/tests/name_resolution/traverse_formal_package/test.out @@ -0,0 +1,85 @@ +Analyzing test.adb +################## + +Resolving xrefs for node +************************************************************************************** + +Expr: + references: + type: None + expected type: None +Expr: + type: None + expected type: None +Traversing generic node <| GenericPackageDecl ["Formal_G"] test.adb:2:4-6:17 [test.adb:16:12] |> +************************************************************************************************ + +Resolving xrefs for node <| ConcreteFormalSubpDecl ["Foo"] test.adb:3:12-3:32 [test.adb:16:12] |> +************************************************************************************************* + +Expr: <| BoxExpr test.adb:3:29-3:31 [test.adb:16:12] |> + type: None + expected type: None + +Resolving xrefs for node <| SubpSpec test.adb:3:12-3:25 [test.adb:16:12] |> +*************************************************************************** + + +Resolving xrefs for node <| SubpSpec test.adb:5:7-5:20 [test.adb:16:12] |> +************************************************************************** + + +Resolving xrefs for node <| EndName test.adb:6:8-6:16 [test.adb:16:12] |> +************************************************************************* + +Expr: <| EndName test.adb:6:8-6:16 [test.adb:16:12] |> + references: + type: None + expected type: None +Expr: <| Id "Formal_G" test.adb:6:8-6:16 [test.adb:16:12] |> + references: + type: None + expected type: None + +Traversing generic node <| PackageBody ["Formal_G"] test.adb:8:4-13:17 [test.adb:16:12] |> +****************************************************************************************** + +Resolving xrefs for node <| SubpSpec test.adb:9:7-9:20 [test.adb:16:12] |> +************************************************************************** + + +Resolving xrefs for node <| CallStmt test.adb:11:10-11:14 [test.adb:16:12] |> +***************************************************************************** + +Expr: <| Id "Foo" test.adb:11:10-11:13 [test.adb:16:12] |> + references: <| DefiningName "Foo" test.adb:3:22-3:25 [test.adb:16:12] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:12:11-12:14 [test.adb:16:12] |> +**************************************************************************** + +Expr: <| EndName test.adb:12:11-12:14 [test.adb:16:12] |> + references: <| DefiningName "Bar" test.adb:9:17-9:20 [test.adb:16:12] |> + type: None + expected type: None +Expr: <| Id "Bar" test.adb:12:11-12:14 [test.adb:16:12] |> + references: <| DefiningName "Bar" test.adb:9:17-9:20 [test.adb:16:12] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:13:8-13:16 [test.adb:16:12] |> +*************************************************************************** + +Expr: <| EndName test.adb:13:8-13:16 [test.adb:16:12] |> + references: <| DefiningName "Formal_G" test.adb:8:17-8:25 [test.adb:16:12] |> + type: None + expected type: None +Expr: <| Id "Formal_G" test.adb:13:8-13:16 [test.adb:16:12] |> + references: <| DefiningName "Formal_G" test.adb:8:17-8:25 [test.adb:16:12] |> + type: None + expected type: None + + + +Done. diff --git a/testsuite/tests/name_resolution/traverse_formal_package/test.yaml b/testsuite/tests/name_resolution/traverse_formal_package/test.yaml new file mode 100644 index 000000000..e17275cc3 --- /dev/null +++ b/testsuite/tests/name_resolution/traverse_formal_package/test.yaml @@ -0,0 +1,3 @@ +driver: name-resolution +traverse_generics: true +input_sources: [test.adb] From 061575973be08064c0d87aeabf851e0eecdd1ce8 Mon Sep 17 00:00:00 2001 From: Romain Beguet Date: Wed, 31 Jan 2024 18:01:17 +0100 Subject: [PATCH 06/11] Fix creation of rebinding entries. The previous code used .map's index parameter *after* some of the formals were filtered out to index unfiltered actuals, therefore indexing the wrong ones. This patch fixes it by doing the filtering afterwards. --- ada/ast.py | 25 +++--- .../generic_formal_object_after_subp/test.adb | 22 +++++ .../generic_formal_object_after_subp/test.out | 80 +++++++++++++++++++ .../test.yaml | 3 + 4 files changed, 119 insertions(+), 11 deletions(-) create mode 100644 testsuite/tests/name_resolution/generic_formal_object_after_subp/test.adb create mode 100644 testsuite/tests/name_resolution/generic_formal_object_after_subp/test.out create mode 100644 testsuite/tests/name_resolution/generic_formal_object_after_subp/test.yaml diff --git a/ada/ast.py b/ada/ast.py index adf5a1351..beb8431bf 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -12314,26 +12314,29 @@ def instantiation_bindings_internal(): Self.nonbound_generic_decl_from_self ._.formal_part.match_param_list( Entity.generic_inst_params, False - ).filter( - lambda pm: And( - Not(pm.actual.assoc.expr.is_a(BoxExpr)), - # Do not put formal subprograms in the rebindings to avoid - # them being eagerly resolved to an actual, as the formal - # part is needed to implement correct name resolution. We - # will use ``BasicDecl.corresponding_actual`` instead to - # manually resolve it. - Not(pm.formal.formal_decl.is_a(GenericFormalSubpDecl)) - ) ).map( lambda i, pm: T.inner_env_assoc.new( key=pm.formal.name.name_symbol, - value=If( + value=Cond( + # Do not put formal subprograms in the rebindings to + # avoid them being eagerly resolved to an actual, as + # the formal part is needed to implement correct name + # resolution. + # We will use ``BasicDecl.corresponding_actual`` + # instead to manually resolve it. + Or(pm.actual.assoc.expr.is_a(BoxExpr), + pm.formal.formal_decl.is_a(GenericFormalSubpDecl)), + No(Expr), + pm.formal.formal_decl.is_a(T.GenericFormalObjDecl), Entity.actual_expr_decls.at(i), + pm.actual.assoc.expr.node ), metadata=T.Metadata.new() ) + ).filter( + lambda env_assoc: Not(env_assoc.value.is_null) ) ) diff --git a/testsuite/tests/name_resolution/generic_formal_object_after_subp/test.adb b/testsuite/tests/name_resolution/generic_formal_object_after_subp/test.adb new file mode 100644 index 000000000..faf69bd5c --- /dev/null +++ b/testsuite/tests/name_resolution/generic_formal_object_after_subp/test.adb @@ -0,0 +1,22 @@ +procedure Test is + package V is + type T is tagged null record; + + function Bar (X : T) return Integer is (1); + end V; + generic + with procedure Foo; + X : V.T; + package Pkg_G is + Y : Integer := X.Bar; + end Pkg_G; + + procedure F is null; + + K : V.T; + + package My_Pkg is new Pkg_G (F, K); + pragma Test_Statement; +begin + null; +end Test; diff --git a/testsuite/tests/name_resolution/generic_formal_object_after_subp/test.out b/testsuite/tests/name_resolution/generic_formal_object_after_subp/test.out new file mode 100644 index 000000000..4e939e3fd --- /dev/null +++ b/testsuite/tests/name_resolution/generic_formal_object_after_subp/test.out @@ -0,0 +1,80 @@ +Analyzing test.adb +################## + +Resolving xrefs for node +************************************************************************************* + +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: + type: + expected type: +Traversing generic node <| GenericPackageDecl ["Pkg_G"] test.adb:7:4-12:14 [test.adb:18:4] |> +********************************************************************************************* + +Resolving xrefs for node <| ConcreteFormalSubpDecl ["Foo"] test.adb:8:12-8:26 [test.adb:18:4] |> +************************************************************************************************ + + +Resolving xrefs for node <| SubpSpec test.adb:8:12-8:25 [test.adb:18:4] |> +************************************************************************** + + +Resolving xrefs for node <| ObjectDecl ["X"] test.adb:9:7-9:15 [test.adb:18:4] |> +********************************************************************************* + +Expr: <| DottedName test.adb:9:11-9:14 [test.adb:18:4] |> + references: + type: None + expected type: None +Expr: <| Id "V" test.adb:9:11-9:12 [test.adb:18:4] |> + references: + type: None + expected type: None +Expr: <| Id "T" test.adb:9:13-9:14 [test.adb:18:4] |> + references: + type: None + expected type: None + +Resolving xrefs for node <| ObjectDecl ["Y"] test.adb:11:7-11:28 [test.adb:18:4] |> +*********************************************************************************** + +Expr: <| Id "Integer" test.adb:11:11-11:18 [test.adb:18:4] |> + references: + type: None + expected type: None +Expr: <| DottedName test.adb:11:22-11:27 [test.adb:18:4] |> + references: + type: + expected type: +Expr: <| Id "X" test.adb:11:22-11:23 [test.adb:18:4] |> + references: None + type: + expected type: +Expr: <| Id "Bar" test.adb:11:24-11:27 [test.adb:18:4] |> + references: + type: + expected type: + +Resolving xrefs for node <| EndName test.adb:12:8-12:13 [test.adb:18:4] |> +************************************************************************** + +Expr: <| EndName test.adb:12:8-12:13 [test.adb:18:4] |> + references: + type: None + expected type: None +Expr: <| Id "Pkg_G" test.adb:12:8-12:13 [test.adb:18:4] |> + references: + type: None + expected type: None + + + +Done. diff --git a/testsuite/tests/name_resolution/generic_formal_object_after_subp/test.yaml b/testsuite/tests/name_resolution/generic_formal_object_after_subp/test.yaml new file mode 100644 index 000000000..e17275cc3 --- /dev/null +++ b/testsuite/tests/name_resolution/generic_formal_object_after_subp/test.yaml @@ -0,0 +1,3 @@ +driver: name-resolution +traverse_generics: true +input_sources: [test.adb] From 3c60a3c01798cb90139ace9a83c58de41840e101 Mon Sep 17 00:00:00 2001 From: Romain Beguet Date: Mon, 18 Mar 2024 10:01:38 +0100 Subject: [PATCH 07/11] Fix handling of formal package renamings in `pkg_env`. --- ada/ast.py | 12 +- .../formal_package_renaming/test.adb | 29 ++++ .../formal_package_renaming/test.out | 128 ++++++++++++++++++ .../formal_package_renaming/test.yaml | 3 + 4 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 testsuite/tests/name_resolution/formal_package_renaming/test.adb create mode 100644 testsuite/tests/name_resolution/formal_package_renaming/test.out create mode 100644 testsuite/tests/name_resolution/formal_package_renaming/test.yaml diff --git a/ada/ast.py b/ada/ast.py index beb8431bf..914026c86 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -18930,8 +18930,16 @@ def pkg_env(from_pkg=T.BasicDecl.entity): # instantiation. pkg.unshed_rebindings(Entity.info.rebindings) ) - is_inst_from_formal = Var(pkg.is_a(T.GenericPackageInstantiation) & - from_pkg.info.from_rebound) + is_inst_from_formal = Var( + # Check whether the package comes from a rebound env in order to + # determine if we have visibility on its formal part. Look at both + # ``from_pkg`` or ``pkg`` as we may have a renaming of a rebound + # package, or a rebound package being a package renaming, and in + # both cases we have visibility on the final renamed package's + # formal part. + pkg.is_a(T.GenericPackageInstantiation) & + (from_pkg.info.from_rebound | pkg.info.from_rebound) + ) env = Var(If( bd.is_a(T.GenericPackageInstantiation) & is_inst_from_formal, diff --git a/testsuite/tests/name_resolution/formal_package_renaming/test.adb b/testsuite/tests/name_resolution/formal_package_renaming/test.adb new file mode 100644 index 000000000..28d39f9c2 --- /dev/null +++ b/testsuite/tests/name_resolution/formal_package_renaming/test.adb @@ -0,0 +1,29 @@ +procedure Test is + generic + with procedure Foo is <>; + package Op_G is + end Op_G; + + + generic + with package Ops is new Op_G (<>); + package Cont is + procedure Bar; + end Cont; + + package body Cont is + package O renames Ops; + + procedure Bar is + begin + O.Foo; + end Bar; + end Cont; + + procedure Foo is null; + package My_Ops is new Op_G; + package My_Cont is new COnt (My_Ops); + pragma Test_Statement; +begin + null; +end Test; diff --git a/testsuite/tests/name_resolution/formal_package_renaming/test.out b/testsuite/tests/name_resolution/formal_package_renaming/test.out new file mode 100644 index 000000000..7d3e96eb7 --- /dev/null +++ b/testsuite/tests/name_resolution/formal_package_renaming/test.out @@ -0,0 +1,128 @@ +Analyzing test.adb +################## + +Resolving xrefs for node +************************************************************************************** + +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Traversing generic node <| GenericPackageDecl ["Cont"] test.adb:8:4-12:13 [test.adb:25:4] |> +******************************************************************************************** + +Resolving xrefs for node <| GenericPackageInstantiation ["Ops"] test.adb:9:12-9:41 [test.adb:25:4] |> +***************************************************************************************************** + +Expr: <| Id "Op_G" test.adb:9:31-9:35 [test.adb:25:4] |> + references: + type: None + expected type: None +Expr: <| BoxExpr test.adb:9:37-9:39 [test.adb:25:4] |> + type: None + expected type: None +Traversing generic node <| GenericPackageDecl ["Op_G"] test.adb:2:4-5:13 [test.adb:24:4] |> +******************************************************************************************* + +Resolving xrefs for node <| ConcreteFormalSubpDecl ["Foo"] test.adb:3:12-3:32 [test.adb:24:4] |> +************************************************************************************************ + +Expr: <| BoxExpr test.adb:3:29-3:31 [test.adb:24:4] |> + type: None + expected type: None + +Resolving xrefs for node <| SubpSpec test.adb:3:12-3:25 [test.adb:24:4] |> +************************************************************************** + + +Resolving xrefs for node <| EndName test.adb:5:8-5:12 [test.adb:24:4] |> +************************************************************************ + +Expr: <| EndName test.adb:5:8-5:12 [test.adb:24:4] |> + references: + type: None + expected type: None +Expr: <| Id "Op_G" test.adb:5:8-5:12 [test.adb:24:4] |> + references: + type: None + expected type: None + + +Resolving xrefs for node <| SubpSpec test.adb:11:7-11:20 [test.adb:25:4] |> +*************************************************************************** + + +Resolving xrefs for node <| EndName test.adb:12:8-12:12 [test.adb:25:4] |> +************************************************************************** + +Expr: <| EndName test.adb:12:8-12:12 [test.adb:25:4] |> + references: + type: None + expected type: None +Expr: <| Id "Cont" test.adb:12:8-12:12 [test.adb:25:4] |> + references: + type: None + expected type: None + +Traversing generic node <| PackageBody ["Cont"] test.adb:14:4-21:13 [test.adb:25:4] |> +************************************************************************************** + +Resolving xrefs for node <| PackageRenamingDecl ["O"] test.adb:15:7-15:29 [test.adb:25:4] |> +******************************************************************************************** + +Expr: <| Id "Ops" test.adb:15:25-15:28 [test.adb:25:4] |> + references: + type: None + expected type: None + +Resolving xrefs for node <| SubpSpec test.adb:17:7-17:20 [test.adb:25:4] |> +*************************************************************************** + + +Resolving xrefs for node <| CallStmt test.adb:19:10-19:16 [test.adb:25:4] |> +**************************************************************************** + +Expr: <| DottedName test.adb:19:10-19:15 [test.adb:25:4] |> + references: <| DefiningName "Foo" test.adb:3:22-3:25 [test.adb:24:4] |> + type: None + expected type: None +Expr: <| Id "O" test.adb:19:10-19:11 [test.adb:25:4] |> + references: <| DefiningName "O" test.adb:15:15-15:16 [test.adb:25:4] |> + type: None + expected type: None +Expr: <| Id "Foo" test.adb:19:12-19:15 [test.adb:25:4] |> + references: <| DefiningName "Foo" test.adb:3:22-3:25 [test.adb:24:4] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:20:11-20:14 [test.adb:25:4] |> +*************************************************************************** + +Expr: <| EndName test.adb:20:11-20:14 [test.adb:25:4] |> + references: <| DefiningName "Bar" test.adb:17:17-17:20 [test.adb:25:4] |> + type: None + expected type: None +Expr: <| Id "Bar" test.adb:20:11-20:14 [test.adb:25:4] |> + references: <| DefiningName "Bar" test.adb:17:17-17:20 [test.adb:25:4] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:21:8-21:12 [test.adb:25:4] |> +************************************************************************** + +Expr: <| EndName test.adb:21:8-21:12 [test.adb:25:4] |> + references: <| DefiningName "Cont" test.adb:14:17-14:21 [test.adb:25:4] |> + type: None + expected type: None +Expr: <| Id "Cont" test.adb:21:8-21:12 [test.adb:25:4] |> + references: <| DefiningName "Cont" test.adb:14:17-14:21 [test.adb:25:4] |> + type: None + expected type: None + + + +Done. diff --git a/testsuite/tests/name_resolution/formal_package_renaming/test.yaml b/testsuite/tests/name_resolution/formal_package_renaming/test.yaml new file mode 100644 index 000000000..e17275cc3 --- /dev/null +++ b/testsuite/tests/name_resolution/formal_package_renaming/test.yaml @@ -0,0 +1,3 @@ +driver: name-resolution +traverse_generics: true +input_sources: [test.adb] From c3012e3523f313b67242f0bb9684b335283bff76 Mon Sep 17 00:00:00 2001 From: Romain Beguet Date: Mon, 18 Mar 2024 17:17:29 +0100 Subject: [PATCH 08/11] Handle primitives of generic formal types in `real_type`. --- ada/ast.py | 37 +++++- .../primitive_of_formal_derived_type/test.adb | 26 +++++ .../primitive_of_formal_derived_type/test.out | 107 ++++++++++++++++++ .../test.yaml | 3 + 4 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 testsuite/tests/name_resolution/primitive_of_formal_derived_type/test.adb create mode 100644 testsuite/tests/name_resolution/primitive_of_formal_derived_type/test.out create mode 100644 testsuite/tests/name_resolution/primitive_of_formal_derived_type/test.yaml diff --git a/ada/ast.py b/ada/ast.py index 914026c86..da700bce6 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -5037,7 +5037,14 @@ def real_type(typ=T.BaseTypeDecl.entity): # cannot come from a subprogram instantiation. Self.shed_subp_rebindings(Entity.info.rebindings), Entity.info.from_rebound - ).cast(BaseTypeDecl), + ).match( + # Since `primitive_real_type` is a node and not an entity, it + # may refer to a formal type, so we need to manually resolve it + # to an actual type using the current rebindings in case they + # are relevant. + lambda ft=FormalTypeDecl.entity: ft.get_actual, + lambda other: other.cast(BaseTypeDecl) + ), # Handle the case where the primitive is defined on an anonymous # access type, by returning an anonymous access type over the @@ -8978,6 +8985,34 @@ class FormalTypeDecl(TypeDecl): default_type = Field(type=T.Name) aspects = Field(type=T.AspectSpec) + @langkit_property(return_type=T.BaseTypeDecl.entity) + def corresponding_actual_impl(rb=T.EnvRebindings): + """ + Retrieves the actual for this formal type decl by finding the generic + formal part in which Self lies in Self's rebindings, and then resolving + the corresponding actual. + """ + return Cond( + rb.is_null, + Entity, + + rb.old_env == Self.parent.node_env, + rb.new_env.get_first( + Entity.defining_name.name_symbol, + lookup=LK.minimal, categories=no_prims + ).cast(BaseTypeDecl), + + Entity.corresponding_actual_impl(rb.get_parent) + ) + + @langkit_property(return_type=T.BaseTypeDecl.entity) + def get_actual(): + """ + For a ``FormalTypeDecl`` we must find the actual by looking in our own + rebindings. See ``corresponding_actual_impl``. + """ + return Entity.corresponding_actual_impl(Entity.info.rebindings) + @langkit_property(return_type=Equation) def xref_equation(): return Entity.super() & Entity.default_type.then( diff --git a/testsuite/tests/name_resolution/primitive_of_formal_derived_type/test.adb b/testsuite/tests/name_resolution/primitive_of_formal_derived_type/test.adb new file mode 100644 index 000000000..8a5d9837b --- /dev/null +++ b/testsuite/tests/name_resolution/primitive_of_formal_derived_type/test.adb @@ -0,0 +1,26 @@ +procedure Test is + package Seqs is + type Seq is null record; + + function No_Seq return Seq is (null record); + end Seqs; + + generic + type Seq_T is new Seqs.Seq; + package Pkg is + procedure Test; + end Pkg; + + package body Pkg is + procedure Test is + X : Seq_T := No_Seq; + begin + null; + end Test; + end Pkg; + + package My_Pkg is new Pkg (Seqs.Seq); + pragma Test_Statement; +begin + null; +end Test; diff --git a/testsuite/tests/name_resolution/primitive_of_formal_derived_type/test.out b/testsuite/tests/name_resolution/primitive_of_formal_derived_type/test.out new file mode 100644 index 000000000..1e4cd286f --- /dev/null +++ b/testsuite/tests/name_resolution/primitive_of_formal_derived_type/test.out @@ -0,0 +1,107 @@ +Analyzing test.adb +################## + +Resolving xrefs for node +************************************************************************************* + +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Traversing generic node <| GenericPackageDecl ["Pkg"] test.adb:8:4-12:12 [test.adb:22:4] |> +******************************************************************************************* + +Resolving xrefs for node <| FormalTypeDecl ["Seq_T"] test.adb:9:7-9:34 [test.adb:22:4] |> +***************************************************************************************** + +Expr: <| DottedName test.adb:9:25-9:33 [test.adb:22:4] |> + references: + type: None + expected type: None +Expr: <| Id "Seqs" test.adb:9:25-9:29 [test.adb:22:4] |> + references: + type: None + expected type: None +Expr: <| Id "Seq" test.adb:9:30-9:33 [test.adb:22:4] |> + references: + type: None + expected type: None + +Resolving xrefs for node <| SubpSpec test.adb:11:7-11:21 [test.adb:22:4] |> +*************************************************************************** + + +Resolving xrefs for node <| EndName test.adb:12:8-12:11 [test.adb:22:4] |> +************************************************************************** + +Expr: <| EndName test.adb:12:8-12:11 [test.adb:22:4] |> + references: + type: None + expected type: None +Expr: <| Id "Pkg" test.adb:12:8-12:11 [test.adb:22:4] |> + references: + type: None + expected type: None + +Traversing generic node <| PackageBody ["Pkg"] test.adb:14:4-20:12 [test.adb:22:4] |> +************************************************************************************* + +Resolving xrefs for node <| SubpSpec test.adb:15:7-15:21 [test.adb:22:4] |> +*************************************************************************** + + +Resolving xrefs for node <| ObjectDecl ["X"] test.adb:16:10-16:30 [test.adb:22:4] |> +************************************************************************************ + +Expr: <| Id "Seq_T" test.adb:16:14-16:19 [test.adb:22:4] |> + references: + type: None + expected type: None +Expr: <| Id "No_Seq" test.adb:16:23-16:29 [test.adb:22:4] |> + references: <| DefiningName "No_Seq" test.adb:5:16-5:22 [test.adb:22:4] |> + type: + expected type: + +Resolving xrefs for node <| NullStmt test.adb:18:10-18:15 [test.adb:22:4] |> +**************************************************************************** + + +Resolving xrefs for node <| EndName test.adb:19:11-19:15 [test.adb:22:4] |> +*************************************************************************** + +Expr: <| EndName test.adb:19:11-19:15 [test.adb:22:4] |> + references: <| DefiningName "Test" test.adb:15:17-15:21 [test.adb:22:4] |> + type: None + expected type: None +Expr: <| Id "Test" test.adb:19:11-19:15 [test.adb:22:4] |> + references: <| DefiningName "Test" test.adb:15:17-15:21 [test.adb:22:4] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:20:8-20:11 [test.adb:22:4] |> +************************************************************************** + +Expr: <| EndName test.adb:20:8-20:11 [test.adb:22:4] |> + references: <| DefiningName "Pkg" test.adb:14:17-14:20 [test.adb:22:4] |> + type: None + expected type: None +Expr: <| Id "Pkg" test.adb:20:8-20:11 [test.adb:22:4] |> + references: <| DefiningName "Pkg" test.adb:14:17-14:20 [test.adb:22:4] |> + type: None + expected type: None + + + +Done. diff --git a/testsuite/tests/name_resolution/primitive_of_formal_derived_type/test.yaml b/testsuite/tests/name_resolution/primitive_of_formal_derived_type/test.yaml new file mode 100644 index 000000000..e17275cc3 --- /dev/null +++ b/testsuite/tests/name_resolution/primitive_of_formal_derived_type/test.yaml @@ -0,0 +1,3 @@ +driver: name-resolution +traverse_generics: true +input_sources: [test.adb] From b59304a9801a61081093eeda1588fac426996304 Mon Sep 17 00:00:00 2001 From: Romain Beguet Date: Thu, 21 Mar 2024 12:33:33 +0100 Subject: [PATCH 09/11] Collapse two rebinding entries when one is rebound by the other. --- ada/ast.py | 110 ++++++++--- .../collapse_rebindings/test.adb | 37 ++++ .../collapse_rebindings/test.out | 183 ++++++++++++++++++ .../collapse_rebindings/test.yaml | 3 + 4 files changed, 311 insertions(+), 22 deletions(-) create mode 100644 testsuite/tests/name_resolution/collapse_rebindings/test.adb create mode 100644 testsuite/tests/name_resolution/collapse_rebindings/test.out create mode 100644 testsuite/tests/name_resolution/collapse_rebindings/test.yaml diff --git a/ada/ast.py b/ada/ast.py index da700bce6..3ba7793a5 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -564,6 +564,64 @@ def remove_rebindings(base=T.EnvRebindings, suffix=T.EnvRebindings): base ) + @langkit_property(return_type=T.EnvRebindings) + def add_rebinding(base=T.EnvRebindings, + old_env=T.LexicalEnv, + new_env=T.LexicalEnv): + """ + Append a new entry ``old_env -> new_env`` to ``base``. This also takes + care of collapsing a subset of the rebindings if ``new_env`` is + actually inside an envinonment which is rebound by an existing entry. + In other words, this collapses generic formal package instantiations + done in a generic context where the actual package is known. + For example in the following snippet: + + .. code:: ada + + generic + package Interface_G is + end Interface_G; + + generic + with package I is new Interface_G (<>); + package Pkg_G is + end Pkg_G; + + package My_Interface is new Interface_G; + package My_Pkg is new Pkg_G (My_Interface); + + Navigating inside ``My_Pkg`` leads us in ``Pkg_G`` with rebindings + ``[My_Pkg]``. From here, navigating inside the instantiation of the + formal package ``I`` would lead us in ``Interface_G`` with rebindings + ``[My_Pkg, I]``. However, ``add_rebinding`` sees that ``I`` is + rebound by the instantiation of ``My_Pkg`` and therefore collapses + the two rebindings from ``[My_Pkg, I]`` to ``[My_Interface]``. + """ + parent_env = Var(new_env.env_node.node_env) + return Cond( + Or( + base.is_null, + Not(parent_env.env_node.is_a(GenericDecl)), + Not(Self.is_rebound(base, parent_env)), + ), + base.append_rebinding(old_env, new_env), + + base.old_env == parent_env, + base.new_env.get_first(new_env.env_node.cast( + GenericPackageInstantiation + ).name.name_symbol, lookup=LK.minimal) + .cast(GenericPackageInstantiation).then( + lambda gpi: Self.add_rebinding( + base.get_parent, + gpi.nonbound_generic_decl_from_self.node.children_env, + gpi.instantiation_env + ), + default_val=base.append_rebinding(old_env, new_env), + ), + + Self.add_rebinding(base.get_parent, old_env, new_env), + ) + @langkit_property(return_type=T.Bool) def is_rebound(base=T.EnvRebindings, old_env=T.LexicalEnv): """ @@ -593,10 +651,11 @@ def insert_rebindings(base=T.EnvRebindings, to_insert=T.EnvRebindings): Self.is_rebound(base, to_insert.old_env), base, - Self.insert_rebindings( - base, - to_insert.get_parent - ).append_rebinding( + Self.add_rebinding( + Self.insert_rebindings( + base, + to_insert.get_parent + ), to_insert.old_env, to_insert.new_env ) @@ -12698,11 +12757,13 @@ def designated_subp(): node=p.node.cast(GenericSubpDecl).subp_decl, info=T.entity_info.new( md=Entity.info.md, - rebindings=Self.insert_rebindings( - p._.decl.info.rebindings, - Entity.info.rebindings - ).append_rebinding( - p.node.children_env, Self.instantiation_env + rebindings=Self.add_rebinding( + Self.insert_rebindings( + p.info.rebindings, + Entity.info.rebindings + ), + p.node.children_env, + Self.instantiation_env ), from_rebound=p.info.from_rebound ) @@ -12735,19 +12796,24 @@ def designated_package(): info=T.entity_info.new( md=p.info.md, - # Take the rebindings from the current context - rebindings=Self.insert_rebindings( - p._.decl.info.rebindings, - Entity.info.rebindings - ) - # Append the rebindings for the current instantiation. - # NOTE: We use the formal env to create rebindings. There, - # we purposefully want the children env of the P node, with - # no rebindings associated, since the rebinding indication - # concerns the *naked* generic. Hence we use - # p.node.children_env. - .append_rebinding(p.node.children_env, - Self.instantiation_env), + rebindings=Self.add_rebinding( + # A subset of ``Entity``'s rebindings were used to + # resolve ``p``, now use ``insert_rebindings`` to add + # the rest of them. + Self.insert_rebindings( + p.info.rebindings, + Entity.info.rebindings + ), + + # Append the rebindings for the current instantiation. + # NOTE: We use the formal env to create rebindings. + # There, we purposefully want the children env of the + # P node, with no rebindings associated, since the + # rebinding indication concerns the *naked* generic. + # Hence we use `p.node.children_env`. + p.node.children_env, + Self.instantiation_env + ), from_rebound=p.info.from_rebound ), ) diff --git a/testsuite/tests/name_resolution/collapse_rebindings/test.adb b/testsuite/tests/name_resolution/collapse_rebindings/test.adb new file mode 100644 index 000000000..124c4bd2e --- /dev/null +++ b/testsuite/tests/name_resolution/collapse_rebindings/test.adb @@ -0,0 +1,37 @@ +procedure Test is + generic + type P is private; + package Base_G is + type T is tagged null record; + + procedure Foo (X : T; Y : P) is null; + end Base_G; + + generic + with package Base is new Base_G (<>); + package Concrete_G is + generic + type U is new Base.T with private; + package Inner_G is + type V is new U with null record; + + procedure Test (X : V; Y : Base.P); + end Inner_G; + end Concrete_G; + + package body Concrete_G is + package body Inner_G is + procedure Test (X : V; Y : Base.P) is + begin + Foo (U (X), Y); + end Test; + end Inner_G; + end Concrete_G; + + package My_Base is new Base_G (Integer); + package My_Concrete is new Concrete_G (My_Base); + package My_Inner is new My_Concrete.Inner_G (My_Base.T); + pragma Test_Statement; +begin + null; +end Test; diff --git a/testsuite/tests/name_resolution/collapse_rebindings/test.out b/testsuite/tests/name_resolution/collapse_rebindings/test.out new file mode 100644 index 000000000..ac28e2aca --- /dev/null +++ b/testsuite/tests/name_resolution/collapse_rebindings/test.out @@ -0,0 +1,183 @@ +Analyzing test.adb +################## + +Resolving xrefs for node +*************************************************************************************** + +Expr: + references: <| DefiningName "Inner_G" test.adb:15:15-15:22 [test.adb:32:4] |> + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: <| DefiningName "Inner_G" test.adb:15:15-15:22 [test.adb:32:4] |> + type: None + expected type: None +Expr: + references: <| DefiningName "T" test.adb:5:12-5:13 [test.adb:31:4] |> + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: <| DefiningName "T" test.adb:5:12-5:13 [test.adb:31:4] |> + type: None + expected type: None +Traversing generic node <| GenericPackageDecl ["Inner_G"] test.adb:13:7-19:19 [test.adb:32:4, test.adb:33:4] |> +*************************************************************************************************************** + +Resolving xrefs for node <| FormalTypeDecl ["U"] test.adb:14:10-14:44 [test.adb:32:4, test.adb:33:4] |> +******************************************************************************************************* + +Expr: <| DottedName test.adb:14:24-14:30 [test.adb:32:4, test.adb:33:4] |> + references: <| DefiningName "T" test.adb:5:12-5:13 [test.adb:31:4] |> + type: None + expected type: None +Expr: <| Id "Base" test.adb:14:24-14:28 [test.adb:32:4, test.adb:33:4] |> + references: + type: None + expected type: None +Expr: <| Id "T" test.adb:14:29-14:30 [test.adb:32:4, test.adb:33:4] |> + references: <| DefiningName "T" test.adb:5:12-5:13 [test.adb:31:4] |> + type: None + expected type: None + +Resolving xrefs for node <| ConcreteTypeDecl ["V"] test.adb:16:10-16:43 [test.adb:32:4, test.adb:33:4] |> +********************************************************************************************************* + +Expr: <| Id "U" test.adb:16:24-16:25 [test.adb:32:4, test.adb:33:4] |> + references: <| DefiningName "T" test.adb:5:12-5:13 [test.adb:31:4] |> + type: None + expected type: None + +Resolving xrefs for node <| SubpSpec test.adb:18:10-18:44 [test.adb:32:4, test.adb:33:4] |> +******************************************************************************************* + + +Resolving xrefs for node <| ParamSpec ["X"] test.adb:18:26-18:31 [test.adb:32:4, test.adb:33:4] |> +************************************************************************************************** + +Expr: <| Id "V" test.adb:18:30-18:31 [test.adb:32:4, test.adb:33:4] |> + references: <| DefiningName "V" test.adb:16:15-16:16 [test.adb:32:4, test.adb:33:4] |> + type: None + expected type: None + +Resolving xrefs for node <| ParamSpec ["Y"] test.adb:18:33-18:43 [test.adb:32:4, test.adb:33:4] |> +************************************************************************************************** + +Expr: <| DottedName test.adb:18:37-18:43 [test.adb:32:4, test.adb:33:4] |> + references: + type: None + expected type: None +Expr: <| Id "Base" test.adb:18:37-18:41 [test.adb:32:4, test.adb:33:4] |> + references: + type: None + expected type: None +Expr: <| Id "P" test.adb:18:42-18:43 [test.adb:32:4, test.adb:33:4] |> + references: + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:19:11-19:18 [test.adb:32:4, test.adb:33:4] |> +****************************************************************************************** + +Expr: <| EndName test.adb:19:11-19:18 [test.adb:32:4, test.adb:33:4] |> + references: + type: None + expected type: None +Expr: <| Id "Inner_G" test.adb:19:11-19:18 [test.adb:32:4, test.adb:33:4] |> + references: + type: None + expected type: None + +Traversing generic node <| PackageBody ["Inner_G"] test.adb:23:7-28:19 [test.adb:32:4, test.adb:33:4] |> +******************************************************************************************************** + +Resolving xrefs for node <| SubpSpec test.adb:24:10-24:44 [test.adb:32:4, test.adb:33:4] |> +******************************************************************************************* + + +Resolving xrefs for node <| ParamSpec ["X"] test.adb:24:26-24:31 [test.adb:32:4, test.adb:33:4] |> +************************************************************************************************** + +Expr: <| Id "V" test.adb:24:30-24:31 [test.adb:32:4, test.adb:33:4] |> + references: <| DefiningName "V" test.adb:16:15-16:16 [test.adb:32:4, test.adb:33:4] |> + type: None + expected type: None + +Resolving xrefs for node <| ParamSpec ["Y"] test.adb:24:33-24:43 [test.adb:32:4, test.adb:33:4] |> +************************************************************************************************** + +Expr: <| DottedName test.adb:24:37-24:43 [test.adb:32:4, test.adb:33:4] |> + references: + type: None + expected type: None +Expr: <| Id "Base" test.adb:24:37-24:41 [test.adb:32:4, test.adb:33:4] |> + references: + type: None + expected type: None +Expr: <| Id "P" test.adb:24:42-24:43 [test.adb:32:4, test.adb:33:4] |> + references: + type: None + expected type: None + +Resolving xrefs for node <| CallStmt test.adb:26:13-26:28 [test.adb:32:4, test.adb:33:4] |> +******************************************************************************************* + +Expr: <| CallExpr test.adb:26:13-26:27 [test.adb:32:4, test.adb:33:4] |> + references: <| DefiningName "Foo" test.adb:7:17-7:20 [test.adb:32:4, test.adb:33:4] |> + type: None + expected type: None +Expr: <| Id "Foo" test.adb:26:13-26:16 [test.adb:32:4, test.adb:33:4] |> + references: <| DefiningName "Foo" test.adb:7:17-7:20 [test.adb:32:4, test.adb:33:4] |> + type: None + expected type: None +Expr: <| CallExpr test.adb:26:18-26:23 [test.adb:32:4, test.adb:33:4] |> + references: <| DefiningName "T" test.adb:5:12-5:13 [test.adb:31:4] |> + type: <| ConcreteTypeDecl ["T"] test.adb:5:7-5:36 [test.adb:31:4] |> + expected type: <| ConcreteTypeDecl ["T"] test.adb:5:7-5:36 [test.adb:31:4] |> +Expr: <| Id "U" test.adb:26:18-26:19 [test.adb:32:4, test.adb:33:4] |> + references: <| DefiningName "T" test.adb:5:12-5:13 [test.adb:31:4] |> + type: None + expected type: None +Expr: <| Id "X" test.adb:26:21-26:22 [test.adb:32:4, test.adb:33:4] |> + references: <| DefiningName "X" test.adb:24:26-24:27 [test.adb:32:4, test.adb:33:4] |> + type: <| ConcreteTypeDecl ["V"] test.adb:16:10-16:43 [test.adb:32:4, test.adb:33:4] |> + expected type: None +Expr: <| Id "Y" test.adb:26:25-26:26 [test.adb:32:4, test.adb:33:4] |> + references: <| DefiningName "Y" test.adb:24:33-24:34 [test.adb:32:4, test.adb:33:4] |> + type: + expected type: + +Resolving xrefs for node <| EndName test.adb:27:14-27:18 [test.adb:32:4, test.adb:33:4] |> +****************************************************************************************** + +Expr: <| EndName test.adb:27:14-27:18 [test.adb:32:4, test.adb:33:4] |> + references: <| DefiningName "Test" test.adb:24:20-24:24 [test.adb:32:4, test.adb:33:4] |> + type: None + expected type: None +Expr: <| Id "Test" test.adb:27:14-27:18 [test.adb:32:4, test.adb:33:4] |> + references: <| DefiningName "Test" test.adb:24:20-24:24 [test.adb:32:4, test.adb:33:4] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:28:11-28:18 [test.adb:32:4, test.adb:33:4] |> +****************************************************************************************** + +Expr: <| EndName test.adb:28:11-28:18 [test.adb:32:4, test.adb:33:4] |> + references: <| DefiningName "Inner_G" test.adb:23:20-23:27 [test.adb:32:4, test.adb:33:4] |> + type: None + expected type: None +Expr: <| Id "Inner_G" test.adb:28:11-28:18 [test.adb:32:4, test.adb:33:4] |> + references: <| DefiningName "Inner_G" test.adb:23:20-23:27 [test.adb:32:4, test.adb:33:4] |> + type: None + expected type: None + + + +Done. diff --git a/testsuite/tests/name_resolution/collapse_rebindings/test.yaml b/testsuite/tests/name_resolution/collapse_rebindings/test.yaml new file mode 100644 index 000000000..e17275cc3 --- /dev/null +++ b/testsuite/tests/name_resolution/collapse_rebindings/test.yaml @@ -0,0 +1,3 @@ +driver: name-resolution +traverse_generics: true +input_sources: [test.adb] From 6d70ce0c2027985314cc1c98aecde30365d2ba92 Mon Sep 17 00:00:00 2001 From: Romain Beguet Date: Thu, 18 Apr 2024 11:58:43 +0200 Subject: [PATCH 10/11] Add tests requiring generalized shedding implementation. --- .../env_rebindings_shedding_2/test.adb | 70 +++++++++++++++++++ .../env_rebindings_shedding_2/test.out | 20 ++++++ .../env_rebindings_shedding_2/test.yaml | 2 + .../env_rebindings_shedding_3/test.adb | 53 ++++++++++++++ .../env_rebindings_shedding_3/test.out | 11 +++ .../env_rebindings_shedding_3/test.yaml | 2 + 6 files changed, 158 insertions(+) create mode 100644 testsuite/tests/name_resolution/env_rebindings_shedding_2/test.adb create mode 100644 testsuite/tests/name_resolution/env_rebindings_shedding_2/test.out create mode 100644 testsuite/tests/name_resolution/env_rebindings_shedding_2/test.yaml create mode 100644 testsuite/tests/name_resolution/env_rebindings_shedding_3/test.adb create mode 100644 testsuite/tests/name_resolution/env_rebindings_shedding_3/test.out create mode 100644 testsuite/tests/name_resolution/env_rebindings_shedding_3/test.yaml diff --git a/testsuite/tests/name_resolution/env_rebindings_shedding_2/test.adb b/testsuite/tests/name_resolution/env_rebindings_shedding_2/test.adb new file mode 100644 index 000000000..76fc26d75 --- /dev/null +++ b/testsuite/tests/name_resolution/env_rebindings_shedding_2/test.adb @@ -0,0 +1,70 @@ +procedure Test is + generic + type E is private; + package Common_G is + generic + package Op_G is + procedure Bar (X : E); + end Op_G; + + generic + with package Op is new Op_G (<>); + package Shared_G is + procedure Foo (X : E); + end Shared_G; + + generic + with package Shared is new Shared_G (<>); + package Iter_G is + procedure Baz; + end Iter_G; + end Common_G; + + package body Common_G is + package body Op_G is + procedure Bar (X : E) is null; + end Op_G; + + package body Shared_G is + procedure Foo (X : E) is + begin + Op.Bar (X); + end Foo; + end Shared_G; + + package body Iter_G is + procedure Baz is null; + end Iter_G; + end Common_G; + + generic + with package Common is new Common_G (<>); + package Pkg is + generic + with package Op is new Common.Op_G (<>); + package Inner_G is + procedure Bar; + end Inner_G; + end Pkg; + + package body Pkg is + package body Inner_G is + package Shared is new Common.Shared_G (Op => Op); + package Iter is new Common.Iter_G (Shared); + + procedure Bar is null; + end Inner_G; + end Pkg; + + package My_Common is new Common_G (Integer); + package My_Pkg is new Pkg (My_Common); + --% pkg_body = node.p_designated_generic_decl.p_body_part + --% iter_inst = pkg_body.findall(lal.GenericPackageInstantiation)[1] + --% iter_gen = iter_inst.p_designated_generic_decl + --% shared_formal = iter_gen.find(lal.GenericPackageInstantiation) + --% shared_gen = shared_formal.p_designated_generic_decl + --% shared_gen.p_body_part.find(lal.CallStmt).p_resolve_names +begin + null; +end Test; + diff --git a/testsuite/tests/name_resolution/env_rebindings_shedding_2/test.out b/testsuite/tests/name_resolution/env_rebindings_shedding_2/test.out new file mode 100644 index 000000000..757e46381 --- /dev/null +++ b/testsuite/tests/name_resolution/env_rebindings_shedding_2/test.out @@ -0,0 +1,20 @@ +Working on node +============================================================================ + +Set 'pkg_body' to 'node.p_designated_generic_decl.p_body_part' +Result: <| PackageBody ["Pkg"] test.adb:50:4-57:12 [test.adb:60:4] |> + +Set 'iter_inst' to 'pkg_body.findall(lal.GenericPackageInstantiation)[1]' +Result: <| GenericPackageInstantiation ["Iter"] test.adb:53:10-53:53 [test.adb:60:4] |> + +Set 'iter_gen' to 'iter_inst.p_designated_generic_decl' +Result: <| GenericPackageDecl ["Iter_G"] test.adb:16:7-20:18 [test.adb:59:4, test.adb:60:4, test.adb:53:10] |> + +Set 'shared_formal' to 'iter_gen.find(lal.GenericPackageInstantiation)' +Result: <| GenericPackageInstantiation ["Shared"] test.adb:17:15-17:51 [test.adb:59:4, test.adb:60:4, test.adb:53:10] |> + +Set 'shared_gen' to 'shared_formal.p_designated_generic_decl' +Result: <| GenericPackageDecl ["Shared_G"] test.adb:10:7-14:20 [test.adb:59:4, test.adb:60:4, test.adb:52:10] |> + +Eval 'shared_gen.p_body_part.find(lal.CallStmt).p_resolve_names' +Result: True diff --git a/testsuite/tests/name_resolution/env_rebindings_shedding_2/test.yaml b/testsuite/tests/name_resolution/env_rebindings_shedding_2/test.yaml new file mode 100644 index 000000000..35ad4d5c4 --- /dev/null +++ b/testsuite/tests/name_resolution/env_rebindings_shedding_2/test.yaml @@ -0,0 +1,2 @@ +driver: inline-playground +input_sources: [test.adb] diff --git a/testsuite/tests/name_resolution/env_rebindings_shedding_3/test.adb b/testsuite/tests/name_resolution/env_rebindings_shedding_3/test.adb new file mode 100644 index 000000000..81ed38c77 --- /dev/null +++ b/testsuite/tests/name_resolution/env_rebindings_shedding_3/test.adb @@ -0,0 +1,53 @@ +procedure Test is + generic + package Common_G is + type U is null record; + + generic + type T is private; + package Shared_G is + procedure Foo (X : T); + procedure Bar (X : U); + end Shared_G; + end Common_G; + + package body Common_G is + package body Shared_G is + procedure Foo (X : T) is null; + procedure Bar (X : U) is null; + end Shared_G; + end Common_G; + + generic + with package Common is new Common_G; + package Pkg is + type T is null record; + + procedure Foo (X : T); + procedure Bar (X : Common.U); + end Pkg; + + package body Pkg is + package Shared is new Common.Shared_G (T => T); + + procedure Foo (X : T) is + begin + Shared.Foo (X); + end Foo; + + procedure Bar (X : Common.U) is + begin + Shared.Bar (X); + end Bar; + end Pkg; + + package My_Common is new Common_G; + package My_Pkg is new Pkg (My_Common); + --% pkg_body = node.p_designated_generic_decl.p_body_part + --% pkg_body.findall(lal.CallStmt)[0].p_resolve_names + --% pkg_body.findall(lal.CallStmt)[1].p_resolve_names +begin + null; +end Test; + + diff --git a/testsuite/tests/name_resolution/env_rebindings_shedding_3/test.out b/testsuite/tests/name_resolution/env_rebindings_shedding_3/test.out new file mode 100644 index 000000000..eac2633fd --- /dev/null +++ b/testsuite/tests/name_resolution/env_rebindings_shedding_3/test.out @@ -0,0 +1,11 @@ +Working on node +============================================================================ + +Set 'pkg_body' to 'node.p_designated_generic_decl.p_body_part' +Result: <| PackageBody ["Pkg"] test.adb:30:4-42:12 [test.adb:45:4] |> + +Eval 'pkg_body.findall(lal.CallStmt)[0].p_resolve_names' +Result: True + +Eval 'pkg_body.findall(lal.CallStmt)[1].p_resolve_names' +Result: True diff --git a/testsuite/tests/name_resolution/env_rebindings_shedding_3/test.yaml b/testsuite/tests/name_resolution/env_rebindings_shedding_3/test.yaml new file mode 100644 index 000000000..35ad4d5c4 --- /dev/null +++ b/testsuite/tests/name_resolution/env_rebindings_shedding_3/test.yaml @@ -0,0 +1,2 @@ +driver: inline-playground +input_sources: [test.adb] From 6d5b8eab8f10d3eb77f902d65a2ac8664652f83c Mon Sep 17 00:00:00 2001 From: Romain Beguet Date: Thu, 18 Apr 2024 12:08:37 +0200 Subject: [PATCH 11/11] Add test with transitive use clause to formal package. --- .../transitive_use_of_formal_package/test.adb | 37 ++++ .../transitive_use_of_formal_package/test.out | 173 ++++++++++++++++++ .../test.yaml | 3 + 3 files changed, 213 insertions(+) create mode 100644 testsuite/tests/name_resolution/transitive_use_of_formal_package/test.adb create mode 100644 testsuite/tests/name_resolution/transitive_use_of_formal_package/test.out create mode 100644 testsuite/tests/name_resolution/transitive_use_of_formal_package/test.yaml diff --git a/testsuite/tests/name_resolution/transitive_use_of_formal_package/test.adb b/testsuite/tests/name_resolution/transitive_use_of_formal_package/test.adb new file mode 100644 index 000000000..db0216a0f --- /dev/null +++ b/testsuite/tests/name_resolution/transitive_use_of_formal_package/test.adb @@ -0,0 +1,37 @@ +procedure Test is + generic + package Common is + generic + type T is private; + package Shared_G is + end Shared_G; + + generic + with package Shared is new Shared_G (<>); + with procedure Foo (X : Shared.T); + package Operation is + use Shared; + + procedure Bar (X : T); + end Operation; + end Common; + + package body Common is + package body Operation is + procedure Bar (X : T) is + begin + Foo (X); + end Bar; + end Operation; + end Common; + + procedure F (X : Integer) is null; + + package C is new Common; + package S is new C.Shared_G (Integer); + package O is new C.Operation (S, F); + pragma Test_Statement; +begin + null; +end Test; + diff --git a/testsuite/tests/name_resolution/transitive_use_of_formal_package/test.out b/testsuite/tests/name_resolution/transitive_use_of_formal_package/test.out new file mode 100644 index 000000000..1e0e243ea --- /dev/null +++ b/testsuite/tests/name_resolution/transitive_use_of_formal_package/test.out @@ -0,0 +1,173 @@ +Analyzing test.adb +################## + +Resolving xrefs for node +******************************************************************************** + +Expr: + references: <| DefiningName "Operation" test.adb:12:15-12:24 [test.adb:30:4] |> + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: <| DefiningName "Operation" test.adb:12:15-12:24 [test.adb:30:4] |> + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Traversing generic node <| GenericPackageDecl ["Operation"] test.adb:9:7-16:21 [test.adb:30:4, test.adb:32:4] |> +**************************************************************************************************************** + +Resolving xrefs for node <| GenericPackageInstantiation ["Shared"] test.adb:10:15-10:51 [test.adb:30:4, test.adb:32:4] |> +************************************************************************************************************************* + +Expr: <| Id "Shared_G" test.adb:10:37-10:45 [test.adb:30:4, test.adb:32:4] |> + references: + type: None + expected type: None +Expr: <| BoxExpr test.adb:10:47-10:49 [test.adb:30:4, test.adb:32:4] |> + type: None + expected type: None +Traversing generic node <| GenericPackageDecl ["Shared_G"] test.adb:4:7-7:20 [test.adb:30:4, test.adb:31:4] |> +************************************************************************************************************** + +Resolving xrefs for node <| FormalTypeDecl ["T"] test.adb:5:10-5:28 [test.adb:30:4, test.adb:31:4] |> +***************************************************************************************************** + + +Resolving xrefs for node <| EndName test.adb:7:11-7:19 [test.adb:30:4, test.adb:31:4] |> +**************************************************************************************** + +Expr: <| EndName test.adb:7:11-7:19 [test.adb:30:4, test.adb:31:4] |> + references: + type: None + expected type: None +Expr: <| Id "Shared_G" test.adb:7:11-7:19 [test.adb:30:4, test.adb:31:4] |> + references: + type: None + expected type: None + + +Resolving xrefs for node <| ConcreteFormalSubpDecl ["Foo"] test.adb:11:15-11:44 [test.adb:30:4, test.adb:32:4] |> +***************************************************************************************************************** + + +Resolving xrefs for node <| SubpSpec test.adb:11:15-11:43 [test.adb:30:4, test.adb:32:4] |> +******************************************************************************************* + + +Resolving xrefs for node <| ParamSpec ["X"] test.adb:11:30-11:42 [test.adb:30:4, test.adb:32:4] |> +************************************************************************************************** + +Expr: <| DottedName test.adb:11:34-11:42 [test.adb:30:4, test.adb:32:4] |> + references: + type: None + expected type: None +Expr: <| Id "Shared" test.adb:11:34-11:40 [test.adb:30:4, test.adb:32:4] |> + references: + type: None + expected type: None +Expr: <| Id "T" test.adb:11:41-11:42 [test.adb:30:4, test.adb:32:4] |> + references: + type: None + expected type: None + +Resolving xrefs for node <| UsePackageClause test.adb:13:10-13:21 [test.adb:30:4, test.adb:32:4] |> +*************************************************************************************************** + +Expr: <| Id "Shared" test.adb:13:14-13:20 [test.adb:30:4, test.adb:32:4] |> + references: + type: None + expected type: None + +Resolving xrefs for node <| SubpSpec test.adb:15:10-15:31 [test.adb:30:4, test.adb:32:4] |> +******************************************************************************************* + + +Resolving xrefs for node <| ParamSpec ["X"] test.adb:15:25-15:30 [test.adb:30:4, test.adb:32:4] |> +************************************************************************************************** + +Expr: <| Id "T" test.adb:15:29-15:30 [test.adb:30:4, test.adb:32:4] |> + references: + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:16:11-16:20 [test.adb:30:4, test.adb:32:4] |> +****************************************************************************************** + +Expr: <| EndName test.adb:16:11-16:20 [test.adb:30:4, test.adb:32:4] |> + references: + type: None + expected type: None +Expr: <| Id "Operation" test.adb:16:11-16:20 [test.adb:30:4, test.adb:32:4] |> + references: + type: None + expected type: None + +Traversing generic node <| PackageBody ["Operation"] test.adb:20:7-25:21 [test.adb:30:4, test.adb:32:4] |> +********************************************************************************************************** + +Resolving xrefs for node <| SubpSpec test.adb:21:10-21:31 [test.adb:30:4, test.adb:32:4] |> +******************************************************************************************* + + +Resolving xrefs for node <| ParamSpec ["X"] test.adb:21:25-21:30 [test.adb:30:4, test.adb:32:4] |> +************************************************************************************************** + +Expr: <| Id "T" test.adb:21:29-21:30 [test.adb:30:4, test.adb:32:4] |> + references: + type: None + expected type: None + +Resolving xrefs for node <| CallStmt test.adb:23:13-23:21 [test.adb:30:4, test.adb:32:4] |> +******************************************************************************************* + +Expr: <| CallExpr test.adb:23:13-23:20 [test.adb:30:4, test.adb:32:4] |> + references: + type: None + expected type: None +Expr: <| Id "Foo" test.adb:23:13-23:16 [test.adb:30:4, test.adb:32:4] |> + references: + type: None + expected type: None +Expr: <| Id "X" test.adb:23:18-23:19 [test.adb:30:4, test.adb:32:4] |> + references: <| DefiningName "X" test.adb:21:25-21:26 [test.adb:30:4, test.adb:32:4] |> + type: + expected type: + +Resolving xrefs for node <| EndName test.adb:24:14-24:17 [test.adb:30:4, test.adb:32:4] |> +****************************************************************************************** + +Expr: <| EndName test.adb:24:14-24:17 [test.adb:30:4, test.adb:32:4] |> + references: <| DefiningName "Bar" test.adb:21:20-21:23 [test.adb:30:4, test.adb:32:4] |> + type: None + expected type: None +Expr: <| Id "Bar" test.adb:24:14-24:17 [test.adb:30:4, test.adb:32:4] |> + references: <| DefiningName "Bar" test.adb:21:20-21:23 [test.adb:30:4, test.adb:32:4] |> + type: None + expected type: None + +Resolving xrefs for node <| EndName test.adb:25:11-25:20 [test.adb:30:4, test.adb:32:4] |> +****************************************************************************************** + +Expr: <| EndName test.adb:25:11-25:20 [test.adb:30:4, test.adb:32:4] |> + references: <| DefiningName "Operation" test.adb:20:20-20:29 [test.adb:30:4, test.adb:32:4] |> + type: None + expected type: None +Expr: <| Id "Operation" test.adb:25:11-25:20 [test.adb:30:4, test.adb:32:4] |> + references: <| DefiningName "Operation" test.adb:20:20-20:29 [test.adb:30:4, test.adb:32:4] |> + type: None + expected type: None + + + +Done. diff --git a/testsuite/tests/name_resolution/transitive_use_of_formal_package/test.yaml b/testsuite/tests/name_resolution/transitive_use_of_formal_package/test.yaml new file mode 100644 index 000000000..e17275cc3 --- /dev/null +++ b/testsuite/tests/name_resolution/transitive_use_of_formal_package/test.yaml @@ -0,0 +1,3 @@ +driver: name-resolution +traverse_generics: true +input_sources: [test.adb]