Skip to content

Commit 35e5576

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Fix for reading elements of named arguments in annotations.
Accidentally found it while running parallel tests for fine-grained dependencies. Change-Id: I5c05444e7d260df27dd2f30e207d486da65054d1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442724 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 86b6584 commit 35e5576

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

pkg/analyzer/lib/src/summary2/ast_binary_reader.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ class AstBinaryReader {
223223
arguments: arguments,
224224
);
225225
node.element = _reader.readElement();
226+
if (arguments != null) {
227+
_resolveNamedExpressions(node.element, arguments);
228+
}
226229
return node;
227230
}
228231

pkg/analyzer/test/src/summary/elements/metadata_test.dart

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,81 @@ library
14521452
''');
14531453
}
14541454

1455+
test_metadata_constructor_namedArgument() async {
1456+
newFile('$testPackageLibPath/a.dart', r'''
1457+
class A {
1458+
const A({required int value});
1459+
}
1460+
''');
1461+
1462+
var library = await buildLibrary(r'''
1463+
import 'a.dart';
1464+
@A(value: 42)
1465+
void f() {}
1466+
''');
1467+
checkElementText(library, r'''
1468+
library
1469+
reference: <testLibrary>
1470+
fragments
1471+
#F0 <testLibraryFragment>
1472+
element: <testLibrary>
1473+
libraryImports
1474+
package:test/a.dart
1475+
functions
1476+
#F1 f (nameOffset:36) (firstTokenOffset:17) (offset:36)
1477+
element: <testLibrary>::@function::f
1478+
metadata
1479+
Annotation
1480+
atSign: @ @17
1481+
name: SimpleIdentifier
1482+
token: A @18
1483+
element: package:test/a.dart::@class::A
1484+
staticType: null
1485+
arguments: ArgumentList
1486+
leftParenthesis: ( @19
1487+
arguments
1488+
NamedExpression
1489+
name: Label
1490+
label: SimpleIdentifier
1491+
token: value @20
1492+
element: package:test/a.dart::@class::A::@constructor::new::@formalParameter::value
1493+
staticType: null
1494+
colon: : @25
1495+
expression: IntegerLiteral
1496+
literal: 42 @27
1497+
staticType: int
1498+
rightParenthesis: ) @29
1499+
element2: package:test/a.dart::@class::A::@constructor::new
1500+
functions
1501+
f
1502+
reference: <testLibrary>::@function::f
1503+
firstFragment: #F1
1504+
metadata
1505+
Annotation
1506+
atSign: @ @17
1507+
name: SimpleIdentifier
1508+
token: A @18
1509+
element: package:test/a.dart::@class::A
1510+
staticType: null
1511+
arguments: ArgumentList
1512+
leftParenthesis: ( @19
1513+
arguments
1514+
NamedExpression
1515+
name: Label
1516+
label: SimpleIdentifier
1517+
token: value @20
1518+
element: package:test/a.dart::@class::A::@constructor::new::@formalParameter::value
1519+
staticType: null
1520+
colon: : @25
1521+
expression: IntegerLiteral
1522+
literal: 42 @27
1523+
staticType: int
1524+
rightParenthesis: ) @29
1525+
element2: package:test/a.dart::@class::A::@constructor::new
1526+
returnType: void
1527+
''');
1528+
}
1529+
14551530
test_metadata_constructorDeclaration_named() async {
14561531
var library = await buildLibrary(
14571532
'const a = null; class C { @a C.named(); }',

0 commit comments

Comments
 (0)