From c693762310c153fb00a5f470d2c681cac7a18269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Th=C3=A9venoux?= Date: Fri, 9 Sep 2022 15:53:00 +0200 Subject: [PATCH] Do not return ancestor's components when calling `P_Aggregate_Params` This change fixes a bug where `P_Aggregate_Params` would return the ancestor's part components if called on an extended aggregate using the ``other`` designator. TN: V829-017 --- ada/ast.py | 13 +++++++--- .../properties/aggregate_params/test.adb | 20 +++++++++++++++ .../properties/aggregate_params/test.out | 25 +++++++++++++++++++ .../properties/aggregate_params/test.yaml | 2 +- user_manual/changes/V829-017.yaml | 8 ++++++ 5 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 testsuite/tests/properties/aggregate_params/test.adb create mode 100644 user_manual/changes/V829-017.yaml diff --git a/ada/ast.py b/ada/ast.py index 43cf263d7..25ad33440 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -4817,7 +4817,8 @@ class ComponentList(BaseFormalParamHolder): @langkit_property(return_type=BaseFormalParamDecl.entity.array, dynamic_vars=[env, default_origin()]) - def abstract_formal_params_for_assocs(assocs=T.AssocList.entity): + def abstract_formal_params_for_assocs(assocs=T.AssocList.entity, + recurse=(Bool, True)): td = Var(Entity.type_decl) discriminants = Var(td.discriminants_list) @@ -4838,7 +4839,8 @@ def abstract_formal_params_for_assocs(assocs=T.AssocList.entity): # able to calculate the list of components belonging to variant parts, # depending on the static value of discriminants. return td.record_def.comps.abstract_formal_params_impl( - discriminants=discriminants_matches + discriminants=discriminants_matches, + recurse=recurse ) @langkit_property(return_type=BaseFormalParamDecl.entity.array) @@ -15147,7 +15149,12 @@ def zip_with_params(): lambda a=T.BaseAggregate: origin.bind(Self, env.bind( Self.node_env, a.expression_type.record_def - ._.components.abstract_formal_params_for_assocs(Entity), + ._.components.abstract_formal_params_for_assocs( + Entity, + # Do not get parent components if `a` is an extended + # aggregate. + recurse=a.ancestor_expr.is_null + ), )), lambda _: No(T.BaseFormalParamDecl.entity.array) diff --git a/testsuite/tests/properties/aggregate_params/test.adb b/testsuite/tests/properties/aggregate_params/test.adb new file mode 100644 index 000000000..0f5b2e127 --- /dev/null +++ b/testsuite/tests/properties/aggregate_params/test.adb @@ -0,0 +1,20 @@ +procedure Test is + type Root is tagged record + X : Integer := 1; + end record; + + type Child is new Root with record + Y : Integer := 2; + end record; + + C : Child := (Root with others => <>); + --% node.f_default_expr.p_aggregate_params + D : Child := (Root'(X => 9) with others => <>); + --% node.f_default_expr.p_aggregate_params + E : Child := (Root'(X => 9) with Y => 4); + --% node.f_default_expr.p_aggregate_params + F : Child := (others => <>); + --% node.f_default_expr.p_aggregate_params +begin + null; +end Test; diff --git a/testsuite/tests/properties/aggregate_params/test.out b/testsuite/tests/properties/aggregate_params/test.out index ec3b52d2a..22475b185 100644 --- a/testsuite/tests/properties/aggregate_params/test.out +++ b/testsuite/tests/properties/aggregate_params/test.out @@ -132,3 +132,28 @@ Working on node Eval 'node.f_expr.p_aggregate_params' Result: [ actual=>, actual=>] + +Working on node +====================================================== + +Eval 'node.f_default_expr.p_aggregate_params' +Result: [ actual=>] + +Working on node +====================================================== + +Eval 'node.f_default_expr.p_aggregate_params' +Result: [ actual=>] + +Working on node +====================================================== + +Eval 'node.f_default_expr.p_aggregate_params' +Result: [ actual=>] + +Working on node +====================================================== + +Eval 'node.f_default_expr.p_aggregate_params' +Result: [ actual=>, + actual=>] diff --git a/testsuite/tests/properties/aggregate_params/test.yaml b/testsuite/tests/properties/aggregate_params/test.yaml index 15464b38e..2e9cb8699 100644 --- a/testsuite/tests/properties/aggregate_params/test.yaml +++ b/testsuite/tests/properties/aggregate_params/test.yaml @@ -1,2 +1,2 @@ driver: inline-playground -input_sources: [recagg.adb] +input_sources: [recagg.adb, test.adb] diff --git a/user_manual/changes/V829-017.yaml b/user_manual/changes/V829-017.yaml new file mode 100644 index 000000000..f097d1616 --- /dev/null +++ b/user_manual/changes/V829-017.yaml @@ -0,0 +1,8 @@ +type: bugfix +short_title: Fix ``P_Aggregate_Params`` property +title: Do not return ancestor's part components when calling ``P_Aggregate_Params`` +description: | + This change fixes a bug where ``P_Aggregate_Params`` would return ancestor's + part components if called on an extended aggregate using the ``other`` + designator. +date: 2022-09-09