@@ -77,6 +77,31 @@ class FunctionReferenceResolver {
77
77
}
78
78
}
79
79
80
+ /// Checks for a type instantiation of a `dynamic` -typed expression.
81
+ ///
82
+ /// Returns `true` if an error was reported, and resolution can stop.
83
+ bool _checkDynamicTypeInstantiation (FunctionReferenceImpl node,
84
+ PrefixedIdentifierImpl function, Element prefixElement) {
85
+ DartType ? prefixType;
86
+ if (prefixElement is VariableElement ) {
87
+ prefixType = prefixElement.type;
88
+ } else if (prefixElement is PropertyAccessorElement ) {
89
+ prefixType = prefixElement.returnType;
90
+ }
91
+
92
+ function.prefix.staticType = prefixType;
93
+ if (prefixType != null && prefixType.isDynamic) {
94
+ _errorReporter.reportErrorForNode (
95
+ CompileTimeErrorCode .GENERIC_METHOD_TYPE_INSTANTIATION_ON_DYNAMIC ,
96
+ function,
97
+ [],
98
+ );
99
+ node.staticType = DynamicTypeImpl .instance;
100
+ return true ;
101
+ }
102
+ return false ;
103
+ }
104
+
80
105
List <DartType > _checkTypeArguments (
81
106
TypeArgumentList typeArgumentList,
82
107
String ? name,
@@ -271,6 +296,36 @@ class FunctionReferenceResolver {
271
296
_resolve (node: node, rawType: member.type, name: propertyName.name);
272
297
}
273
298
299
+ /// Resolve a possible function tearoff of a [FunctionElement] receiver.
300
+ ///
301
+ /// There are three possible valid cases: tearing off the `call` method of a
302
+ /// function element, tearing off an extension element declared on [Function] ,
303
+ /// and tearing off an extension element declared on a function type.
304
+ ExecutableElement ? _resolveFunctionElementFunction (
305
+ Expression receiver,
306
+ SimpleIdentifier methodName,
307
+ FunctionElement receiverElement,
308
+ ) {
309
+ if (methodName.name == FunctionElement .CALL_METHOD_NAME ) {
310
+ return receiverElement;
311
+ }
312
+
313
+ var methodElement = _resolver.typePropertyResolver
314
+ .resolve (
315
+ receiver: receiver,
316
+ receiverType: receiverElement.type,
317
+ name: methodName.name,
318
+ propertyErrorEntity: methodName,
319
+ nameErrorEntity: methodName,
320
+ )
321
+ .getter;
322
+ if (methodElement != null && methodElement.isStatic) {
323
+ _reportInvalidAccessToStaticMember (methodName, methodElement,
324
+ implicitReceiver: false );
325
+ }
326
+ return methodElement;
327
+ }
328
+
274
329
void _resolvePrefixedIdentifierFunction (
275
330
FunctionReferenceImpl node, PrefixedIdentifierImpl function) {
276
331
var prefixElement = function.prefix.scopeLookupResult! .getter;
@@ -287,14 +342,15 @@ class FunctionReferenceResolver {
287
342
}
288
343
289
344
function.prefix.staticElement = prefixElement;
345
+ var functionName = function.identifier.name;
346
+
290
347
if (prefixElement is PrefixElement ) {
291
- var functionName = function.identifier.name;
292
348
var functionElement = prefixElement.scope.lookup (functionName).getter;
293
349
if (functionElement == null ) {
294
350
_errorReporter.reportErrorForNode (
295
351
CompileTimeErrorCode .UNDEFINED_PREFIXED_NAME ,
296
352
function.identifier,
297
- [function.identifier.name , function.prefix.name],
353
+ [functionName , function.prefix.name],
298
354
);
299
355
function.staticType = DynamicTypeImpl .instance;
300
356
node.staticType = DynamicTypeImpl .instance;
@@ -306,21 +362,17 @@ class FunctionReferenceResolver {
306
362
}
307
363
}
308
364
309
- DartType ? prefixType;
310
- if (prefixElement is VariableElement ) {
311
- prefixType = prefixElement.type;
312
- } else if (prefixElement is PropertyAccessorElement ) {
313
- prefixType = prefixElement.returnType;
365
+ if (_checkDynamicTypeInstantiation (node, function, prefixElement)) {
366
+ return ;
314
367
}
315
368
316
- function.prefix.staticType = prefixType;
317
- if (prefixType != null && prefixType.isDynamic ) {
318
- _errorReporter. reportErrorForNode (
319
- CompileTimeErrorCode . GENERIC_METHOD_TYPE_INSTANTIATION_ON_DYNAMIC ,
320
- function ,
321
- [] ,
369
+ if (prefixElement is FunctionElement &&
370
+ functionName == FunctionElement . CALL_METHOD_NAME ) {
371
+ _resolve (
372
+ node : node ,
373
+ rawType : prefixElement.type ,
374
+ name : functionName ,
322
375
);
323
- node.staticType = DynamicTypeImpl .instance;
324
376
return ;
325
377
}
326
378
@@ -337,7 +389,7 @@ class FunctionReferenceResolver {
337
389
_resolve (
338
390
node: node,
339
391
rawType: methodElement.type,
340
- name: function.identifier.name ,
392
+ name: functionName ,
341
393
);
342
394
return ;
343
395
}
@@ -686,6 +738,8 @@ class FunctionReferenceResolver {
686
738
}
687
739
if (receiverElement is ClassElement ) {
688
740
return _resolveStaticElement (receiverElement, name);
741
+ } else if (receiverElement is FunctionElement ) {
742
+ return _resolveFunctionElementFunction (receiver, name, receiverElement);
689
743
} else if (receiverElement is TypeAliasElement ) {
690
744
var aliasedType = receiverElement.aliasedType;
691
745
if (aliasedType is InterfaceType ) {
0 commit comments