Skip to content

Commit

Permalink
Merge branch 'topic/1103' into 'master'
Browse files Browse the repository at this point in the history
Do not resolve box expression in a record component association

Closes #1103

See merge request eng/libadalang/libadalang!1429
  • Loading branch information
thvnx committed Oct 25, 2023
2 parents 67c8737 + bbf46e9 commit 2eb7dfa
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 53 deletions.
50 changes: 33 additions & 17 deletions ada/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -15912,36 +15912,52 @@ def record_assoc_equation():
lambda n: n.is_a(OthersDesignator)
))

# Whether this is the `component_choice_list => <>` association (in
# that case the component_choice_list's components can not be of the
# same type).
is_box_expr = Var(Entity.expr.is_a(T.BoxExpr))

return If(
Not(is_others_assoc),

matches.logic_all(lambda match: And(
Bind(
match.actual.assoc.expr.expected_type_var,
match.formal.formal_decl.type_expression.designated_type
# If expr is a box expr do not resolve it since it doesn't have
# a name nor type.
If(
is_box_expr,
LogicTrue(),
Bind(
match.actual.assoc.expr.expected_type_var,
match.formal.formal_decl
.type_expression.designated_type
)
& match.actual.assoc.expr.sub_equation
& match.actual.assoc.expr.matches_expected_assign_type
),
match.actual.assoc.expr.sub_equation,
match.actual.assoc.expr.matches_expected_assign_type,
match.actual.name.then(
lambda n: Bind(n.ref_var, match.formal.formal_decl),
LogicTrue()
)
)),

# Since all the formals designated by "others" should have the same
# type, we look for the first formal that was not yet matched and
# use its type as the type of the expression associated to
# "others".
agg.first_unmatched_formal.then(
lambda unmatched_formal:
Bind(
Entity.expr.expected_type_var,
unmatched_formal.formal_decl
.type_expression.designated_type
# type (iff expr is not a box expr), we look for the first formal
# that was not yet matched and use its type as the type of the
# expression associated to "others".
If(
is_box_expr,
LogicTrue(),
agg.first_unmatched_formal.then(
lambda unmatched_formal:
Bind(
Entity.expr.expected_type_var,
unmatched_formal.formal_decl
.type_expression.designated_type
)
& Entity.expr.sub_equation
& Entity.expr.matches_expected_type,
default_val=LogicTrue()
)
& Entity.expr.sub_equation
& Entity.expr.matches_expected_type,
default_val=LogicTrue()
)
)

Expand Down
5 changes: 5 additions & 0 deletions testsuite/tests/name_resolution/aggregates/test.adb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ procedure Test is
pragma Test_Statement;
DEF4 : T5 := (D1 | D2 | D3 => <>, C1 => <>, C2 => <>);
pragma Test_Statement;

A : constant T3 := (C1|C2 => <>);
pragma Test_Statement;
B : constant T3 := (others => <>);
pragma Test_Statement;
begin
null;
end Test;
104 changes: 70 additions & 34 deletions testsuite/tests/name_resolution/aggregates/test.out
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Expr: <Aggregate test.adb:39:33-39:47>
type: <ConcreteTypeDecl ["T2"] test.adb:4:4-12:15>
expected type: <ConcreteTypeDecl ["T2"] test.adb:4:4-12:15>
Expr: <BoxExpr test.adb:39:44-39:46>
type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
expected type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
type: None
expected type: None

Resolving xrefs for node <ObjectDecl ["P"] test.adb:41:4-41:52>
***************************************************************
Expand All @@ -46,8 +46,8 @@ Expr: <Id "E1" test.adb:41:34-41:36>
type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
expected type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
Expr: <BoxExpr test.adb:41:48-41:50>
type: <ConcreteTypeDecl ["Integer"] __standard:4:3-4:54>
expected type: <ConcreteTypeDecl ["Integer"] __standard:4:3-4:54>
type: None
expected type: None

Resolving xrefs for node <ObjectDecl ["Q"] test.adb:43:4-43:43>
***************************************************************
Expand Down Expand Up @@ -138,8 +138,8 @@ Expr: <Int test.adb:48:30-48:31>
type: <ConcreteTypeDecl ["Universal_Int_Type_"] __standard:116:3-116:45>
expected type: <ConcreteTypeDecl ["Integer"] __standard:4:3-4:54>
Expr: <BoxExpr test.adb:48:43-48:45>
type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
expected type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
type: None
expected type: None

Resolving xrefs for node <ObjectDecl ["H"] test.adb:50:4-50:45>
***************************************************************
Expand Down Expand Up @@ -260,8 +260,8 @@ Expr: <Int test.adb:57:39-57:40>
type: <ConcreteTypeDecl ["Universal_Int_Type_"] __standard:116:3-116:45>
expected type: <ConcreteTypeDecl ["Integer"] __standard:4:3-4:54>
Expr: <BoxExpr test.adb:57:52-57:54>
type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
expected type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
type: None
expected type: None

Resolving xrefs for node <ObjectDecl ["Z"] test.adb:60:4-60:72>
***************************************************************
Expand Down Expand Up @@ -302,8 +302,8 @@ Expr: <Id "E2" test.adb:60:54-60:56>
type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
expected type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
Expr: <BoxExpr test.adb:60:68-60:70>
type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
expected type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
type: None
expected type: None

Resolving xrefs for node <ObjectDecl ["DEF1"] test.adb:63:4-63:27>
******************************************************************
Expand All @@ -320,8 +320,8 @@ Expr: <Id "D" test.adb:63:18-63:19>
type: None
expected type: None
Expr: <BoxExpr test.adb:63:23-63:25>
type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
expected type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
type: None
expected type: None

Resolving xrefs for node <ObjectDecl ["DEF2"] test.adb:65:4-65:47>
******************************************************************
Expand All @@ -338,22 +338,22 @@ Expr: <Id "D" test.adb:65:18-65:19>
type: None
expected type: None
Expr: <BoxExpr test.adb:65:23-65:25>
type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
expected type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
type: None
expected type: None
Expr: <Id "C1" test.adb:65:27-65:29>
references: <DefiningName "C1" test.adb:22:13-22:15>
type: None
expected type: None
Expr: <BoxExpr test.adb:65:33-65:35>
type: <ConcreteTypeDecl ["Integer"] __standard:4:3-4:54>
expected type: <ConcreteTypeDecl ["Integer"] __standard:4:3-4:54>
type: None
expected type: None
Expr: <Id "C2" test.adb:65:37-65:39>
references: <DefiningName "C2" test.adb:23:13-23:15>
type: None
expected type: None
Expr: <BoxExpr test.adb:65:43-65:45>
type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
expected type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
type: None
expected type: None

Resolving xrefs for node <ObjectDecl ["DEF3"] test.adb:67:4-67:68>
******************************************************************
Expand All @@ -370,36 +370,36 @@ Expr: <Id "D1" test.adb:67:18-67:20>
type: None
expected type: None
Expr: <BoxExpr test.adb:67:24-67:26>
type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
expected type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
type: None
expected type: None
Expr: <Id "D2" test.adb:67:28-67:30>
references: <DefiningName "D2" test.adb:29:17-29:19>
type: None
expected type: None
Expr: <BoxExpr test.adb:67:34-67:36>
type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
expected type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
type: None
expected type: None
Expr: <Id "D3" test.adb:67:38-67:40>
references: <DefiningName "D3" test.adb:29:32-29:34>
type: None
expected type: None
Expr: <BoxExpr test.adb:67:44-67:46>
type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
expected type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
type: None
expected type: None
Expr: <Id "C1" test.adb:67:48-67:50>
references: <DefiningName "C1" test.adb:32:13-32:15>
type: None
expected type: None
Expr: <BoxExpr test.adb:67:54-67:56>
type: <ConcreteTypeDecl ["Integer"] __standard:4:3-4:54>
expected type: <ConcreteTypeDecl ["Integer"] __standard:4:3-4:54>
type: None
expected type: None
Expr: <Id "C2" test.adb:67:58-67:60>
references: <DefiningName "C2" test.adb:33:13-33:15>
type: None
expected type: None
Expr: <BoxExpr test.adb:67:64-67:66>
type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
expected type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
type: None
expected type: None

Resolving xrefs for node <ObjectDecl ["DEF4"] test.adb:69:4-69:58>
******************************************************************
Expand All @@ -424,22 +424,58 @@ Expr: <Id "D3" test.adb:69:28-69:30>
type: None
expected type: None
Expr: <BoxExpr test.adb:69:34-69:36>
type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
expected type: <ConcreteTypeDecl ["T1"] test.adb:2:4-2:24>
type: None
expected type: None
Expr: <Id "C1" test.adb:69:38-69:40>
references: <DefiningName "C1" test.adb:32:13-32:15>
type: None
expected type: None
Expr: <BoxExpr test.adb:69:44-69:46>
type: <ConcreteTypeDecl ["Integer"] __standard:4:3-4:54>
expected type: <ConcreteTypeDecl ["Integer"] __standard:4:3-4:54>
type: None
expected type: None
Expr: <Id "C2" test.adb:69:48-69:50>
references: <DefiningName "C2" test.adb:33:13-33:15>
type: None
expected type: None
Expr: <BoxExpr test.adb:69:54-69:56>
type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
expected type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
type: None
expected type: None

Resolving xrefs for node <ObjectDecl ["A"] test.adb:72:4-72:37>
***************************************************************

Expr: <Id "T3" test.adb:72:17-72:19>
references: <DefiningName "T3" test.adb:14:9-14:11>
type: None
expected type: None
Expr: <Aggregate test.adb:72:23-72:36>
type: <ConcreteTypeDecl ["T3"] test.adb:14:4-17:15>
expected type: <ConcreteTypeDecl ["T3"] test.adb:14:4-17:15>
Expr: <Id "C1" test.adb:72:24-72:26>
references: <DefiningName "C1" test.adb:15:7-15:9>
type: None
expected type: None
Expr: <Id "C2" test.adb:72:27-72:29>
references: <DefiningName "C2" test.adb:16:7-16:9>
type: None
expected type: None
Expr: <BoxExpr test.adb:72:33-72:35>
type: None
expected type: None

Resolving xrefs for node <ObjectDecl ["B"] test.adb:74:4-74:38>
***************************************************************

Expr: <Id "T3" test.adb:74:17-74:19>
references: <DefiningName "T3" test.adb:14:9-14:11>
type: None
expected type: None
Expr: <Aggregate test.adb:74:23-74:37>
type: <ConcreteTypeDecl ["T3"] test.adb:14:4-17:15>
expected type: <ConcreteTypeDecl ["T3"] test.adb:14:4-17:15>
Expr: <BoxExpr test.adb:74:34-74:36>
type: None
expected type: None


Done.
4 changes: 2 additions & 2 deletions testsuite/tests/name_resolution/first_attribute/test.out
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ Expr: <Aggregate testfirst.adb:13:31-13:45>
type: <ConcreteTypeDecl ["Lol"] testfirst.adb:9:4-11:15>
expected type: <ConcreteTypeDecl ["Lol"] testfirst.adb:9:4-11:15>
Expr: <BoxExpr testfirst.adb:13:42-13:44>
type: <ConcreteTypeDecl ["A"] testfirst.adb:2:4-2:50>
expected type: <ConcreteTypeDecl ["A"] testfirst.adb:2:4-2:50>
type: None
expected type: None

Resolving xrefs for node <SubpSpec testfirst.adb:13:4-13:27>
************************************************************
Expand Down

0 comments on commit 2eb7dfa

Please sign in to comment.