Skip to content

Commit efa73a4

Browse files
author
John Messerly
committed
fix #26812, function types should support the call method
[email protected] Review URL: https://codereview.chromium.org/2226903003 .
1 parent fa11df1 commit efa73a4

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,9 @@ class ElementResolver extends SimpleAstVisitor<Object> {
643643
}
644644
staticElement = _resolveElement(typeReference, methodName);
645645
} else {
646-
DartType staticType = _getStaticType(target);
646+
DartType staticType = _resolver.strongMode
647+
? _getStaticTypeOrFunctionType(target)
648+
: _getStaticType(target);
647649
DartType propagatedType = _getPropagatedType(target);
648650
staticElement = _resolveInvokedElementWithTarget(
649651
target, staticType, methodName, isConditional);
@@ -1544,10 +1546,7 @@ class ElementResolver extends SimpleAstVisitor<Object> {
15441546
* type analysis.
15451547
*/
15461548
DartType _getStaticType(Expression expression) {
1547-
if (expression is NullLiteral) {
1548-
return _resolver.typeProvider.bottomType;
1549-
}
1550-
DartType staticType = _resolveTypeParameter(expression.staticType);
1549+
DartType staticType = _getStaticTypeOrFunctionType(expression);
15511550
if (staticType is FunctionType) {
15521551
//
15531552
// All function types are subtypes of 'Function', which is itself a
@@ -1558,6 +1557,13 @@ class ElementResolver extends SimpleAstVisitor<Object> {
15581557
return staticType;
15591558
}
15601559

1560+
DartType _getStaticTypeOrFunctionType(Expression expression) {
1561+
if (expression is NullLiteral) {
1562+
return _resolver.typeProvider.bottomType;
1563+
}
1564+
return _resolveTypeParameter(expression.staticType);
1565+
}
1566+
15611567
/**
15621568
* Check for a generic method & apply type arguments if any were passed.
15631569
*/
@@ -2224,6 +2230,10 @@ class ElementResolver extends SimpleAstVisitor<Object> {
22242230
return element;
22252231
} else if (target is SimpleIdentifier) {
22262232
Element targetElement = target.staticElement;
2233+
if (targetType is FunctionType &&
2234+
methodName.name == FunctionElement.CALL_METHOD_NAME) {
2235+
return targetElement;
2236+
}
22272237
if (targetElement is PrefixElement) {
22282238
if (isConditional) {
22292239
_resolver.errorReporter.reportErrorForNode(

pkg/analyzer/test/src/task/strong/checker_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ test() {
113113
''');
114114
}
115115

116+
void test_callMethodOnFunctions() {
117+
checkFile(r'''
118+
void f(int x) => print(x);
119+
main() {
120+
f.call(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/'hi');
121+
}
122+
''');
123+
}
124+
116125
void test_castsInConditions() {
117126
checkFile('''
118127
main() {

0 commit comments

Comments
 (0)