Skip to content

Commit

Permalink
nameres: fix record assoc expression matching type predicate
Browse files Browse the repository at this point in the history
When building record assoc expression equation, the predicate used to
check that expected_type matches the expression type should use the
predicate that consider that assoc expression is a for-assignment
match.
  • Loading branch information
thvnx committed Apr 13, 2023
1 parent 5dd6369 commit 68e2690
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ada/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -15453,7 +15453,7 @@ def record_assoc_equation():
match.formal.formal_decl.type_expression.designated_type
),
match.actual.assoc.expr.sub_equation,
match.actual.assoc.expr.matches_expected_type,
match.actual.assoc.expr.matches_expected_assign_type,
match.actual.name.then(
lambda n: Bind(n.ref_var, match.formal.formal_decl),
LogicTrue()
Expand Down
23 changes: 23 additions & 0 deletions testsuite/tests/name_resolution/anonymous_type_match/test.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
procedure Test is
type Obj is tagged null record;

type T is record
Class : access Obj'Class;
end record;

type Obj2 is new Obj with record
I : Integer;
end record;

procedure P (Prm : access Obj2);

procedure P (Prm : access Obj2) is
E : T := T'(Class => Prm);
pragma Test_Statement;
begin
null;
end P;

begin
null;
end Test;
32 changes: 32 additions & 0 deletions testsuite/tests/name_resolution/anonymous_type_match/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Analyzing test.adb
##################

Resolving xrefs for node <ObjectDecl ["E"] test.adb:15:8-15:34>
***************************************************************

Expr: <Id "T" test.adb:15:12-15:13>
references: <DefiningName "T" test.adb:4:9-4:10>
type: None
expected type: None
Expr: <QualExpr test.adb:15:17-15:33>
references: <DefiningName "T" test.adb:4:9-4:10>
type: <ConcreteTypeDecl ["T"] test.adb:4:4-6:15>
expected type: <ConcreteTypeDecl ["T"] test.adb:4:4-6:15>
Expr: <Id "T" test.adb:15:17-15:18>
references: <DefiningName "T" test.adb:4:9-4:10>
type: None
expected type: None
Expr: <Aggregate test.adb:15:19-15:33>
type: <ConcreteTypeDecl ["T"] test.adb:4:4-6:15>
expected type: <ConcreteTypeDecl ["T"] test.adb:4:4-6:15>
Expr: <Id "Class" test.adb:15:20-15:25>
references: <DefiningName "Class" test.adb:5:7-5:12>
type: None
expected type: None
Expr: <Id "Prm" test.adb:15:29-15:32>
references: <DefiningName "Prm" test.adb:14:17-14:20>
type: <AnonymousTypeDecl ["None"] test.adb:14:23-14:34>
expected type: <AnonymousTypeDecl ["None"] test.adb:5:15-5:31>


Done.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
driver: name-resolution
input_sources: [test.adb]

0 comments on commit 68e2690

Please sign in to comment.