Skip to content

Commit 3e3d647

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Perform more resolution of method invocations involving extension methods
Change-Id: Ia8060a8a595003341657422bdb68a7b53153f272 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110346 Reviewed-by: Phil Quitslund <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent bf4bde6 commit 3e3d647

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ class MethodInvocationResolver {
328328
return;
329329
}
330330
nameNode.staticElement = member;
331+
_setResolution(node, member.type);
331332
return;
332333
}
333334

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

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,21 @@ class ExtensionMethodTest extends DriverResolutionTest {
2323
..contextFeatures = new FeatureSet.forTesting(
2424
sdkVersion: '2.3.0', additionalFeatures: [Feature.extension_methods]);
2525

26+
test_accessStaticWithinInstance() async {
27+
await assertNoErrorsInCode('''
28+
class A {}
29+
extension E on A {
30+
static void a() {}
31+
void b() { a(); }
32+
}
33+
''');
34+
var invocation = findNode.methodInvocation('a();');
35+
assertElement(invocation, findElement.method('a'));
36+
assertInvokeType(invocation, 'void Function()');
37+
}
38+
2639
test_getter_noMatch() async {
27-
await assertErrorCodesInCode(r'''
40+
await assertErrorsInCode(r'''
2841
class B { }
2942
3043
extension A on B { }
@@ -33,7 +46,10 @@ f() {
3346
B b = B();
3447
int x = b.a;
3548
}
36-
''', [StaticTypeWarningCode.UNDEFINED_GETTER]);
49+
''', [
50+
error(HintCode.UNUSED_LOCAL_VARIABLE, 60, 1),
51+
error(StaticTypeWarningCode.UNDEFINED_GETTER, 66, 1),
52+
]);
3753
}
3854

3955
test_getter_oneMatch() async {
@@ -78,18 +94,6 @@ f() {
7894
expect(invocation.identifier.staticElement, declaration.declaredElement);
7995
}
8096

81-
test_accessStaticWithinInstance() async {
82-
await assertNoErrorsInCode('''
83-
class A {}
84-
extension E on A {
85-
static void a() {}
86-
void b() { a(); }
87-
}
88-
''');
89-
var invocation = findNode.methodInvocation('a();');
90-
assertElement(invocation, findElement.method('a'));
91-
}
92-
9397
test_method_moreSpecificThanPlatform() async {
9498
//
9599
// An extension with on type clause T1 is more specific than another
@@ -125,6 +129,7 @@ f() {
125129

126130
var invocation = findNode.methodInvocation('c.a()');
127131
assertElement(invocation, findElement.method('a', of: 'Core2_Ext'));
132+
assertInvokeType(invocation, 'void Function()');
128133
}
129134

130135
test_method_noMatch() async {
@@ -181,6 +186,7 @@ f() {
181186

182187
var invocation = findNode.methodInvocation('b.a()');
183188
assertElement(invocation, findElement.method('a'));
189+
assertInvokeType(invocation, 'void Function()');
184190
}
185191

186192
test_method_privateExtension() async {
@@ -242,6 +248,7 @@ f() {
242248

243249
var invocation = findNode.methodInvocation('b.a()');
244250
assertElement(invocation, findElement.method('a', of: 'B_Ext'));
251+
assertInvokeType(invocation, 'void Function()');
245252
}
246253

247254
@failingTest
@@ -270,6 +277,7 @@ main() {
270277

271278
var invocation = findNode.methodInvocation('x.f(o)');
272279
assertElement(invocation, findElement.method('f', of: 'B_Ext'));
280+
assertInvokeType(invocation, 'void Function(T)');
273281
}
274282

275283
test_method_specificSubtypeMatchPlatform() async {
@@ -300,6 +308,7 @@ f() {
300308

301309
var invocation = findNode.methodInvocation('c.a()');
302310
assertElement(invocation, findElement.method('a', of: 'Core2_Ext'));
311+
assertInvokeType(invocation, 'void Function()');
303312
}
304313

305314
test_method_unnamedExtension() async {
@@ -331,7 +340,7 @@ extension E2 on A {}
331340
}
332341

333342
test_setter_noMatch() async {
334-
await assertErrorCodesInCode(r'''
343+
await assertErrorsInCode(r'''
335344
class B { }
336345
337346
extension A on B {
@@ -341,7 +350,9 @@ f() {
341350
B b = B();
342351
b.a = 1;
343352
}
344-
''', [StaticTypeWarningCode.UNDEFINED_SETTER]);
353+
''', [
354+
error(StaticTypeWarningCode.UNDEFINED_SETTER, 58, 1),
355+
]);
345356
}
346357

347358
test_setter_oneMatch() async {

0 commit comments

Comments
 (0)