Skip to content

Commit 8fb6f68

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Support resolution of this
Change-Id: I491703d7dd7c6eed6eebf3597ba33d10cfdb2958 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110402 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 5357056 commit 8fb6f68

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

pkg/analyzer/lib/dart/ast/ast.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,6 +2114,9 @@ abstract class ExtendsClause implements AstNode {
21142114
///
21152115
/// Clients may not extend, implement or mix-in this class.
21162116
abstract class ExtensionDeclaration implements CompilationUnitMember {
2117+
@override
2118+
ExtensionElement get declaredElement;
2119+
21172120
/// Return the type that is being extended.
21182121
TypeAnnotation get extendedType;
21192122

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4452,6 +4452,29 @@ class ResolverVisitor extends ScopedVisitor {
44524452
}
44534453
}
44544454

4455+
@override
4456+
void visitExtensionDeclaration(ExtensionDeclaration node) {
4457+
//
4458+
// Resolve the metadata in the library scope
4459+
// and associate the annotations with the element.
4460+
//
4461+
if (node.metadata != null) {
4462+
node.metadata.accept(this);
4463+
ElementResolver.resolveMetadata(node);
4464+
}
4465+
//
4466+
// Continue the extension resolution.
4467+
//
4468+
try {
4469+
typeAnalyzer.thisType = node.declaredElement.extendedType;
4470+
super.visitExtensionDeclaration(node);
4471+
node.accept(elementResolver);
4472+
node.accept(typeAnalyzer);
4473+
} finally {
4474+
typeAnalyzer.thisType = null;
4475+
}
4476+
}
4477+
44554478
@override
44564479
void visitForElementInScope(ForElement node) {
44574480
ForLoopParts forLoopParts = node.forLoopParts;

pkg/analyzer/test/src/dart/resolution/extension_method_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,31 @@ f() {
9494
expect(invocation.identifier.staticElement, declaration.declaredElement);
9595
}
9696

97+
test_getter_usingThis() async {
98+
await assertNoErrorsInCode('''
99+
class C {}
100+
101+
extension E on C {
102+
int get a => 1;
103+
int m() => this.a;
104+
}
105+
''');
106+
var access = findNode.propertyAccess('this.a');
107+
assertPropertyAccess(access, findElement.getter('a'), 'int');
108+
}
109+
110+
@failingTest
111+
test_metadata() async {
112+
await assertNoErrorsInCode('''
113+
const int ann = 1;
114+
class C {}
115+
@ann
116+
extension E on C {}
117+
''');
118+
var annotation = findNode.annotation('@ann');
119+
assertElement(annotation, findElement.topVar('ann'));
120+
}
121+
97122
test_method_moreSpecificThanPlatform() async {
98123
//
99124
// An extension with on type clause T1 is more specific than another

0 commit comments

Comments
 (0)