@@ -8,6 +8,7 @@ import 'package:analyzer/dart/ast/ast.dart';
8
8
import 'package:analyzer/dart/ast/token.dart' ;
9
9
import 'package:analyzer/dart/ast/visitor.dart' ;
10
10
import 'package:analyzer/dart/element/element.dart' ;
11
+ import 'package:analyzer/dart/element/type.dart' ;
11
12
import 'package:analyzer/exception/exception.dart' ;
12
13
import 'package:analyzer/src/dart/ast/ast.dart' ;
13
14
import 'package:analyzer/src/dart/element/builder.dart' ;
@@ -225,6 +226,7 @@ class DeclarationResolver extends RecursiveAstVisitor<Object> {
225
226
elementName: functionName.name + '=' );
226
227
}
227
228
}
229
+ _setGenericFunctionType (node.returnType, element.returnType);
228
230
node.functionExpression.element = element;
229
231
_walker._elementHolder? .addFunction (element);
230
232
_walk (new ElementWalker .forExecutable (element, _enclosingUnit), () {
@@ -278,6 +280,7 @@ class DeclarationResolver extends RecursiveAstVisitor<Object> {
278
280
@override
279
281
Object visitGenericFunctionType (GenericFunctionType node) {
280
282
GenericFunctionTypeElement element = node.type.element;
283
+ _setGenericFunctionType (node.returnType, element.returnType);
281
284
_walk (new ElementWalker .forGenericFunctionType (element), () {
282
285
super .visitGenericFunctionType (node);
283
286
});
@@ -288,8 +291,7 @@ class DeclarationResolver extends RecursiveAstVisitor<Object> {
288
291
Object visitGenericTypeAlias (GenericTypeAlias node) {
289
292
GenericTypeAliasElementImpl element =
290
293
_match (node.name, _walker.getTypedef ());
291
- (node.functionType as GenericFunctionTypeImpl )? .type =
292
- element.function? .type;
294
+ _setGenericFunctionType (node.functionType, element.function? .type);
293
295
_walk (new ElementWalker .forGenericTypeAlias (element), () {
294
296
super .visitGenericTypeAlias (node);
295
297
});
@@ -357,6 +359,7 @@ class DeclarationResolver extends RecursiveAstVisitor<Object> {
357
359
elementName: nameOfMethod + '=' );
358
360
}
359
361
}
362
+ _setGenericFunctionType (node.returnType, element.returnType);
360
363
_walk (new ElementWalker .forExecutable (element, _enclosingUnit), () {
361
364
super .visitMethodDeclaration (node);
362
365
});
@@ -393,10 +396,7 @@ class DeclarationResolver extends RecursiveAstVisitor<Object> {
393
396
ParameterElement element =
394
397
_match (node.identifier, _walker.getParameter ());
395
398
(node as SimpleFormalParameterImpl ).element = element;
396
- TypeAnnotation type = node.type;
397
- if (type is GenericFunctionTypeImpl ) {
398
- type.type = element.type;
399
- }
399
+ _setGenericFunctionType (node.type, element.type);
400
400
_walk (new ElementWalker .forParameter (element), () {
401
401
super .visitSimpleFormalParameter (node);
402
402
});
@@ -463,10 +463,13 @@ class DeclarationResolver extends RecursiveAstVisitor<Object> {
463
463
if (_walker.elementBuilder != null ) {
464
464
return _walker.elementBuilder.visitVariableDeclarationList (node);
465
465
} else {
466
- super .visitVariableDeclarationList (node);
466
+ node.variables.accept (this );
467
+ VariableElement firstVariable = node.variables[0 ].element;
468
+ _setGenericFunctionType (node.type, firstVariable.type);
469
+ node.type? .accept (this );
467
470
if (node.parent is ! FieldDeclaration &&
468
471
node.parent is ! TopLevelVariableDeclaration ) {
469
- _resolveMetadata (node, node.metadata, node.variables[ 0 ].element );
472
+ _resolveMetadata (node, node.metadata, firstVariable );
470
473
}
471
474
return null ;
472
475
}
@@ -537,6 +540,15 @@ class DeclarationResolver extends RecursiveAstVisitor<Object> {
537
540
}
538
541
}
539
542
543
+ /**
544
+ * If the given [typeNode] is a [GenericFunctionType] , set its [type] .
545
+ */
546
+ void _setGenericFunctionType (TypeAnnotation typeNode, DartType type) {
547
+ if (typeNode is GenericFunctionTypeImpl ) {
548
+ typeNode.type = type;
549
+ }
550
+ }
551
+
540
552
/**
541
553
* Recurses through the element model and AST, verifying that all elements are
542
554
* matched.
0 commit comments