Skip to content

Commit

Permalink
Do not return ancestor's components when calling P_Aggregate_Params
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thvnx committed Sep 12, 2022
1 parent 060864d commit c693762
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
13 changes: 10 additions & 3 deletions ada/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions testsuite/tests/properties/aggregate_params/test.adb
Original file line number Diff line number Diff line change
@@ -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;
25 changes: 25 additions & 0 deletions testsuite/tests/properties/aggregate_params/test.out
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,28 @@ Working on node <AssignStmt recagg.adb:90:4-90:16>
Eval 'node.f_expr.p_aggregate_params'
Result: [<ParamActual param=<DefiningName recagg.adb:41:10-41:11> actual=<Int recagg.adb:90:10-90:11>>,
<ParamActual param=<DefiningName recagg.adb:46:10-46:11> actual=<Int recagg.adb:90:13-90:14>>]

Working on node <ObjectDecl ["C"] test.adb:10:4-10:42>
======================================================

Eval 'node.f_default_expr.p_aggregate_params'
Result: [<ParamActual param=<DefiningName test.adb:7:7-7:8> actual=<BoxExpr test.adb:10:38-10:40>>]

Working on node <ObjectDecl ["D"] test.adb:12:4-12:51>
======================================================

Eval 'node.f_default_expr.p_aggregate_params'
Result: [<ParamActual param=<DefiningName test.adb:7:7-7:8> actual=<BoxExpr test.adb:12:47-12:49>>]

Working on node <ObjectDecl ["E"] test.adb:14:4-14:45>
======================================================

Eval 'node.f_default_expr.p_aggregate_params'
Result: [<ParamActual param=<DefiningName test.adb:7:7-7:8> actual=<Int test.adb:14:42-14:43>>]

Working on node <ObjectDecl ["F"] test.adb:16:4-16:32>
======================================================

Eval 'node.f_default_expr.p_aggregate_params'
Result: [<ParamActual param=<DefiningName test.adb:3:7-3:8> actual=<BoxExpr test.adb:16:28-16:30>>,
<ParamActual param=<DefiningName test.adb:7:7-7:8> actual=<BoxExpr test.adb:16:28-16:30>>]
2 changes: 1 addition & 1 deletion testsuite/tests/properties/aggregate_params/test.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
driver: inline-playground
input_sources: [recagg.adb]
input_sources: [recagg.adb, test.adb]
8 changes: 8 additions & 0 deletions user_manual/changes/V829-017.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c693762

Please sign in to comment.