Tests for using getter in MethodInvocation.

R=brianwilkerson@google.com

Change-Id: If63713da5e01608b63d697360faac1fce376550b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/111261
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2019-07-30 16:03:10 +00:00 committed by commit-bot@chromium.org
parent c12deff784
commit 92633cf4af
3 changed files with 47 additions and 4 deletions

View file

@ -339,7 +339,8 @@ class MethodInvocationResolver {
return;
}
nameNode.staticElement = member;
_setResolution(node, member.type);
var calleeType = _getCalleeType(node, member);
_setResolution(node, calleeType);
return;
}
@ -371,9 +372,6 @@ class MethodInvocationResolver {
throw new UnsupportedError('cascaded extension override');
}
// TODO(brianwilkerson) Handle the case where the name resolved to a getter.
// It might be that the getter returns a function that is being invoked, or
// it might be an error to have an argument list.
nameNode.staticElement = member;
var calleeType = _getCalleeType(node, member);
_setResolution(node, calleeType);

View file

@ -187,6 +187,27 @@ f(C c) {
assertInvokeType(invocation, 'int Function(int)');
}
test_instance_getter_methodInvocation() async {
await assertNoErrorsInCode('''
class C {}
extension E on C {
double Function(int) get a => (b) => 2.0;
}
f(C c) {
c.a(0);
}
''');
var invocation = findNode.methodInvocation('a(0);');
assertMethodInvocation(
invocation,
findElement.getter('a'),
'double Function(int)',
expectedMethodNameType: 'double Function(int) Function()',
);
}
test_instance_getter_noMatch() async {
await assertErrorsInCode(r'''
class C {}

View file

@ -135,6 +135,30 @@ void f(A a) {
validatePropertyAccess();
}
test_getter_noPrefix_noTypeArguments_methodInvocation() async {
await assertNoErrorsInCode('''
class A {}
extension E on A {
double Function(int) get g => (b) => 2.0;
}
void f(A a) {
E(a).g(0);
}
''');
findDeclarationAndOverride(declarationName: 'E ', overrideSearch: 'E(a)');
validateOverride();
var invocation = findNode.methodInvocation('g(0);');
assertMethodInvocation(
invocation,
findElement.getter('g'),
'double Function(int)',
expectedMethodNameType: 'double Function(int) Function()',
);
}
test_getter_noPrefix_typeArguments() async {
await assertNoErrorsInCode('''
class A {}