Issue 54549. Fix resolution for dartCoreFunction.call tear-off.

Bug: https://github.com/dart-lang/sdk/issues/54549
Change-Id: I8e64cfc530434af2a26fc6cbf0d22204a1107392
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345364
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
Konstantin Shcheglov 2024-01-09 18:19:13 +00:00 committed by Commit Queue
parent 20cd635717
commit c338b85771
3 changed files with 34 additions and 7 deletions

View file

@ -430,11 +430,12 @@ class PropertyElementResolver with ScopeHelpers {
var targetType = target.typeOrThrow;
if (targetType is FunctionType &&
propertyName.name == FunctionElement.CALL_METHOD_NAME) {
return PropertyElementResolverResult(
functionTypeCallType: targetType,
);
if (propertyName.name == FunctionElement.CALL_METHOD_NAME) {
if (targetType is FunctionType || targetType.isDartCoreFunction) {
return PropertyElementResolverResult(
functionTypeCallType: targetType,
);
}
}
if (targetType is VoidType) {

View file

@ -126,6 +126,30 @@ AssignmentExpression
''');
}
test_functionClass_call_read() async {
await assertNoErrorsInCode('''
void f(Function a) {
a.call;
}
''');
final node = findNode.singlePrefixedIdentifier;
assertResolvedNodeText(node, r'''
PrefixedIdentifier
prefix: SimpleIdentifier
token: a
staticElement: self::@function::f::@parameter::a
staticType: Function
period: .
identifier: SimpleIdentifier
token: call
staticElement: <null>
staticType: Function
staticElement: <null>
staticType: Function
''');
}
test_hasReceiver_typeAlias_staticGetter() async {
await assertNoErrorsInCode(r'''
class A {

View file

@ -444,11 +444,13 @@ void f<X extends num, Y extends X>(Y y) {
}
test_propertyAccess_functionClass_call() async {
await assertNoErrorsInCode('''
await assertErrorsInCode('''
void f(Function a) {
return (a).call;
}
''');
''', [
error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 30, 8),
]);
}
test_propertyAccess_functionType_call() async {