Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 2551023005: Prepare for decoupling analyzer ASTs from element model. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.generated.resolver; 5 library analyzer.src.generated.resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/resolution_accessors.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 11 import 'package:analyzer/dart/ast/token.dart';
11 import 'package:analyzer/dart/ast/visitor.dart'; 12 import 'package:analyzer/dart/ast/visitor.dart';
12 import 'package:analyzer/dart/element/element.dart'; 13 import 'package:analyzer/dart/element/element.dart';
13 import 'package:analyzer/dart/element/type.dart'; 14 import 'package:analyzer/dart/element/type.dart';
14 import 'package:analyzer/dart/element/visitor.dart'; 15 import 'package:analyzer/dart/element/visitor.dart';
15 import 'package:analyzer/error/error.dart'; 16 import 'package:analyzer/error/error.dart';
16 import 'package:analyzer/error/listener.dart'; 17 import 'package:analyzer/error/listener.dart';
17 import 'package:analyzer/exception/exception.dart'; 18 import 'package:analyzer/exception/exception.dart';
18 import 'package:analyzer/src/dart/ast/ast.dart'; 19 import 'package:analyzer/src/dart/ast/ast.dart';
19 import 'package:analyzer/src/dart/ast/utilities.dart'; 20 import 'package:analyzer/src/dart/ast/utilities.dart';
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 this._currentLibrary, this._manager, 99 this._currentLibrary, this._manager,
99 {TypeSystem typeSystem}) 100 {TypeSystem typeSystem})
100 : _nullType = typeProvider.nullType, 101 : _nullType = typeProvider.nullType,
101 _futureNullType = typeProvider.futureNullType, 102 _futureNullType = typeProvider.futureNullType,
102 _typeSystem = typeSystem ?? new TypeSystemImpl() { 103 _typeSystem = typeSystem ?? new TypeSystemImpl() {
103 inDeprecatedMember = _currentLibrary.isDeprecated; 104 inDeprecatedMember = _currentLibrary.isDeprecated;
104 } 105 }
105 106
106 @override 107 @override
107 Object visitAnnotation(Annotation node) { 108 Object visitAnnotation(Annotation node) {
108 if (node.elementAnnotation?.isFactory == true) { 109 if (elementAnnotationForAnnotation(node)?.isFactory == true) {
109 AstNode parent = node.parent; 110 AstNode parent = node.parent;
110 if (parent is MethodDeclaration) { 111 if (parent is MethodDeclaration) {
111 _checkForInvalidFactory(parent); 112 _checkForInvalidFactory(parent);
112 } else { 113 } else {
113 _errorReporter 114 _errorReporter
114 .reportErrorForNode(HintCode.INVALID_FACTORY_ANNOTATION, node, []); 115 .reportErrorForNode(HintCode.INVALID_FACTORY_ANNOTATION, node, []);
115 } 116 }
116 } 117 }
117 return super.visitAnnotation(node); 118 return super.visitAnnotation(node);
118 } 119 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 187 }
187 188
188 @override 189 @override
189 Object visitConditionalExpression(ConditionalExpression node) { 190 Object visitConditionalExpression(ConditionalExpression node) {
190 _checkForPossibleNullCondition(node.condition); 191 _checkForPossibleNullCondition(node.condition);
191 return super.visitConditionalExpression(node); 192 return super.visitConditionalExpression(node);
192 } 193 }
193 194
194 @override 195 @override
195 Object visitConstructorDeclaration(ConstructorDeclaration node) { 196 Object visitConstructorDeclaration(ConstructorDeclaration node) {
196 if (node.element.isFactory) { 197 if (elementForConstructorDeclaration(node).isFactory) {
197 if (node.body is BlockFunctionBody) { 198 if (node.body is BlockFunctionBody) {
198 // Check the block for a return statement, if not, create the hint. 199 // Check the block for a return statement, if not, create the hint.
199 if (!ExitDetector.exits(node.body)) { 200 if (!ExitDetector.exits(node.body)) {
200 _errorReporter.reportErrorForNode( 201 _errorReporter.reportErrorForNode(
201 HintCode.MISSING_RETURN, node, [node.returnType.name]); 202 HintCode.MISSING_RETURN, node, [node.returnType.name]);
202 } 203 }
203 } 204 }
204 } 205 }
205 return super.visitConstructorDeclaration(node); 206 return super.visitConstructorDeclaration(node);
206 } 207 }
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 // or have the logic centralized elsewhere, instead of doing this logic 642 // or have the logic centralized elsewhere, instead of doing this logic
642 // here. 643 // here.
643 displayName = element.enclosingElement.displayName; 644 displayName = element.enclosingElement.displayName;
644 if (!element.displayName.isEmpty) { 645 if (!element.displayName.isEmpty) {
645 displayName = "$displayName.${element.displayName}"; 646 displayName = "$displayName.${element.displayName}";
646 } 647 }
647 } else if (displayName == FunctionElement.CALL_METHOD_NAME && 648 } else if (displayName == FunctionElement.CALL_METHOD_NAME &&
648 node is MethodInvocation && 649 node is MethodInvocation &&
649 node.staticInvokeType is InterfaceType) { 650 node.staticInvokeType is InterfaceType) {
650 displayName = 651 displayName =
651 "${node.staticInvokeType.displayName}.${element.displayName}"; 652 "${staticInvokeTypeForInvocationExpression(node).displayName}.${elem ent.displayName}";
652 } 653 }
653 _errorReporter.reportErrorForNode( 654 _errorReporter.reportErrorForNode(
654 HintCode.DEPRECATED_MEMBER_USE, node, [displayName]); 655 HintCode.DEPRECATED_MEMBER_USE, node, [displayName]);
655 } 656 }
656 } 657 }
657 658
658 /** 659 /**
659 * For [SimpleIdentifier]s, only call [checkForDeprecatedMemberUse] 660 * For [SimpleIdentifier]s, only call [checkForDeprecatedMemberUse]
660 * if the node is not in a declaration context. 661 * if the node is not in a declaration context.
661 * 662 *
(...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after
2280 * elements. 2281 * elements.
2281 * 2282 *
2282 * The resulting AST must have everything resolved that would have been resolved 2283 * The resulting AST must have everything resolved that would have been resolved
2283 * by a [DirectiveElementBuilder]. 2284 * by a [DirectiveElementBuilder].
2284 */ 2285 */
2285 class DirectiveResolver extends SimpleAstVisitor { 2286 class DirectiveResolver extends SimpleAstVisitor {
2286 LibraryElement _enclosingLibrary; 2287 LibraryElement _enclosingLibrary;
2287 2288
2288 @override 2289 @override
2289 void visitCompilationUnit(CompilationUnit node) { 2290 void visitCompilationUnit(CompilationUnit node) {
2290 _enclosingLibrary = node.element.library; 2291 _enclosingLibrary = elementForCompilationUnit(node).library;
2291 for (Directive directive in node.directives) { 2292 for (Directive directive in node.directives) {
2292 directive.accept(this); 2293 directive.accept(this);
2293 } 2294 }
2294 } 2295 }
2295 2296
2296 @override 2297 @override
2297 void visitExportDirective(ExportDirective node) { 2298 void visitExportDirective(ExportDirective node) {
2298 int nodeOffset = node.offset; 2299 int nodeOffset = node.offset;
2299 node.element = null; 2300 node.element = null;
2300 for (ExportElement element in _enclosingLibrary.exports) { 2301 for (ExportElement element in _enclosingLibrary.exports) {
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after
3587 bool _enableDart2JSHints = false; 3588 bool _enableDart2JSHints = false;
3588 3589
3589 /** 3590 /**
3590 * The inheritance manager used to find overridden methods. 3591 * The inheritance manager used to find overridden methods.
3591 */ 3592 */
3592 InheritanceManager _manager; 3593 InheritanceManager _manager;
3593 3594
3594 GatherUsedLocalElementsVisitor _usedLocalElementsVisitor; 3595 GatherUsedLocalElementsVisitor _usedLocalElementsVisitor;
3595 3596
3596 HintGenerator(this._compilationUnits, this._context, this._errorListener) { 3597 HintGenerator(this._compilationUnits, this._context, this._errorListener) {
3597 _library = _compilationUnits[0].element.library; 3598 _library = elementForCompilationUnit(_compilationUnits[0]).library;
3598 _usedImportedElementsVisitor = 3599 _usedImportedElementsVisitor =
3599 new GatherUsedImportedElementsVisitor(_library); 3600 new GatherUsedImportedElementsVisitor(_library);
3600 _enableDart2JSHints = _context.analysisOptions.dart2jsHint; 3601 _enableDart2JSHints = _context.analysisOptions.dart2jsHint;
3601 _manager = 3602 _manager =
3602 new InheritanceManager(_library, includeAbstractFromSuperclasses: true); 3603 new InheritanceManager(_library, includeAbstractFromSuperclasses: true);
3603 _usedLocalElementsVisitor = new GatherUsedLocalElementsVisitor(_library); 3604 _usedLocalElementsVisitor = new GatherUsedLocalElementsVisitor(_library);
3604 } 3605 }
3605 3606
3606 void generateForLibrary() { 3607 void generateForLibrary() {
3607 PerformanceStatistics.hints.makeCurrentWhile(() { 3608 PerformanceStatistics.hints.makeCurrentWhile(() {
3608 int length = _compilationUnits.length; 3609 int length = _compilationUnits.length;
3609 for (int i = 0; i < length; i++) { 3610 for (int i = 0; i < length; i++) {
3610 CompilationUnit unit = _compilationUnits[i]; 3611 CompilationUnit unit = _compilationUnits[i];
3611 CompilationUnitElement element = unit.element; 3612 CompilationUnitElement element = unit.element;
3612 if (element != null) { 3613 if (element != null) {
3613 _generateForCompilationUnit(unit, element.source); 3614 _generateForCompilationUnit(unit, element.source);
3614 } 3615 }
3615 } 3616 }
3616 CompilationUnit definingUnit = _compilationUnits[0]; 3617 CompilationUnit definingUnit = _compilationUnits[0];
3617 ErrorReporter definingUnitErrorReporter = 3618 ErrorReporter definingUnitErrorReporter = new ErrorReporter(
3618 new ErrorReporter(_errorListener, definingUnit.element.source); 3619 _errorListener, elementForCompilationUnit(definingUnit).source);
3619 { 3620 {
3620 ImportsVerifier importsVerifier = new ImportsVerifier(); 3621 ImportsVerifier importsVerifier = new ImportsVerifier();
3621 importsVerifier.addImports(definingUnit); 3622 importsVerifier.addImports(definingUnit);
3622 importsVerifier 3623 importsVerifier
3623 .removeUsedElements(_usedImportedElementsVisitor.usedElements); 3624 .removeUsedElements(_usedImportedElementsVisitor.usedElements);
3624 importsVerifier.generateDuplicateImportHints(definingUnitErrorReporter); 3625 importsVerifier.generateDuplicateImportHints(definingUnitErrorReporter);
3625 importsVerifier.generateUnusedImportHints(definingUnitErrorReporter); 3626 importsVerifier.generateUnusedImportHints(definingUnitErrorReporter);
3626 importsVerifier.generateUnusedShownNameHints(definingUnitErrorReporter); 3627 importsVerifier.generateUnusedShownNameHints(definingUnitErrorReporter);
3627 } 3628 }
3628 _library.accept(new UnusedLocalElementsVerifier( 3629 _library.accept(new UnusedLocalElementsVerifier(
(...skipping 2152 matching lines...) Expand 10 before | Expand all | Expand 10 after
5781 // We do not visit the label because it needs to be visited in the context 5782 // We do not visit the label because it needs to be visited in the context
5782 // of the statement. 5783 // of the statement.
5783 // 5784 //
5784 node.accept(elementResolver); 5785 node.accept(elementResolver);
5785 node.accept(typeAnalyzer); 5786 node.accept(typeAnalyzer);
5786 return null; 5787 return null;
5787 } 5788 }
5788 5789
5789 @override 5790 @override
5790 Object visitDefaultFormalParameter(DefaultFormalParameter node) { 5791 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
5791 InferenceContext.setType(node.defaultValue, node.parameter.element?.type); 5792 InferenceContext.setType(
5793 node.defaultValue, elementForFormalParameter(node.parameter)?.type);
5792 super.visitDefaultFormalParameter(node); 5794 super.visitDefaultFormalParameter(node);
5793 ParameterElement element = node.element; 5795 ParameterElement element = node.element;
5794 if (element.initializer != null && node.defaultValue != null) { 5796 if (element.initializer != null && node.defaultValue != null) {
5795 (element.initializer as FunctionElementImpl).returnType = 5797 (element.initializer as FunctionElementImpl).returnType =
5796 node.defaultValue.staticType; 5798 node.defaultValue.staticType;
5797 } 5799 }
5798 // Clone the ASTs for default formal parameters, so that we can use them 5800 // Clone the ASTs for default formal parameters, so that we can use them
5799 // during constant evaluation. 5801 // during constant evaluation.
5800 if (!_hasSerializedConstantInitializer(element)) { 5802 if (!_hasSerializedConstantInitializer(element)) {
5801 (element as ConstVariableElement).constantInitializer = 5803 (element as ConstVariableElement).constantInitializer =
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
5899 // We visit the iterator before the loop variable because the loop variable 5901 // We visit the iterator before the loop variable because the loop variable
5900 // cannot be in scope while visiting the iterator. 5902 // cannot be in scope while visiting the iterator.
5901 // 5903 //
5902 Expression iterable = node.iterable; 5904 Expression iterable = node.iterable;
5903 DeclaredIdentifier loopVariable = node.loopVariable; 5905 DeclaredIdentifier loopVariable = node.loopVariable;
5904 SimpleIdentifier identifier = node.identifier; 5906 SimpleIdentifier identifier = node.identifier;
5905 if (loopVariable?.type?.type != null) { 5907 if (loopVariable?.type?.type != null) {
5906 InterfaceType targetType = (node.awaitKeyword == null) 5908 InterfaceType targetType = (node.awaitKeyword == null)
5907 ? typeProvider.iterableType 5909 ? typeProvider.iterableType
5908 : typeProvider.streamType; 5910 : typeProvider.streamType;
5909 InferenceContext.setType( 5911 InferenceContext.setType(iterable,
5910 iterable, targetType.instantiate([loopVariable.type.type])); 5912 targetType.instantiate([typeForTypeName(loopVariable.type)]));
5911 } 5913 }
5912 iterable?.accept(this); 5914 iterable?.accept(this);
5913 loopVariable?.accept(this); 5915 loopVariable?.accept(this);
5914 identifier?.accept(this); 5916 identifier?.accept(this);
5915 Statement body = node.body; 5917 Statement body = node.body;
5916 if (body != null) { 5918 if (body != null) {
5917 _overrideManager.enterScope(); 5919 _overrideManager.enterScope();
5918 try { 5920 try {
5919 if (loopVariable != null && iterable != null) { 5921 if (loopVariable != null && iterable != null) {
5920 LocalVariableElement loopElement = loopVariable.element; 5922 LocalVariableElement loopElement = loopVariable.element;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
6010 _overrideManager.enterScope(); 6012 _overrideManager.enterScope();
6011 try { 6013 try {
6012 DartType functionType = InferenceContext.getType(node); 6014 DartType functionType = InferenceContext.getType(node);
6013 if (functionType is FunctionType) { 6015 if (functionType is FunctionType) {
6014 functionType = 6016 functionType =
6015 matchFunctionTypeParameters(node.typeParameters, functionType); 6017 matchFunctionTypeParameters(node.typeParameters, functionType);
6016 if (functionType is FunctionType) { 6018 if (functionType is FunctionType) {
6017 _inferFormalParameterList(node.parameters, functionType); 6019 _inferFormalParameterList(node.parameters, functionType);
6018 6020
6019 DartType returnType; 6021 DartType returnType;
6020 if (isFutureThen(node.staticParameterElement?.enclosingElement)) { 6022 ParameterElement parameterElement =
6023 staticParameterElementForExpression(node);
6024 if (isFutureThen(parameterElement?.enclosingElement)) {
6021 var futureThenType = 6025 var futureThenType =
6022 InferenceContext.getContext(node.parent) as FunctionType; 6026 InferenceContext.getContext(node.parent) as FunctionType;
6023 6027
6024 // Pretend the return type of Future<T>.then<S> first parameter is 6028 // Pretend the return type of Future<T>.then<S> first parameter is
6025 // 6029 //
6026 // T -> (S | Future<S>) 6030 // T -> (S | Future<S>)
6027 // 6031 //
6028 // We can't represent this in Dart so we populate it here during 6032 // We can't represent this in Dart so we populate it here during
6029 // inference. 6033 // inference.
6030 var typeParamS = 6034 var typeParamS =
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
6171 // 6175 //
6172 // For example it can infer this case: 6176 // For example it can infer this case:
6173 // 6177 //
6174 // class E<S, T> extends A<C<S>, T> { ... } 6178 // class E<S, T> extends A<C<S>, T> { ... }
6175 // A<C<int>, String> a0 = /*infer<int, String>*/new E("hello"); 6179 // A<C<int>, String> a0 = /*infer<int, String>*/new E("hello");
6176 // 6180 //
6177 // See _inferArgumentTypesFromContext in this file for use of it. 6181 // See _inferArgumentTypesFromContext in this file for use of it.
6178 List<DartType> targs = 6182 List<DartType> targs =
6179 inferenceContext.matchTypes(classTypeName.type, contextType); 6183 inferenceContext.matchTypes(classTypeName.type, contextType);
6180 if (targs != null && targs.any((t) => !t.isDynamic)) { 6184 if (targs != null && targs.any((t) => !t.isDynamic)) {
6181 ClassElement classElement = classTypeName.type.element; 6185 ClassElement classElement = typeForTypeName(classTypeName).element;
6182 InterfaceType rawType = classElement.type; 6186 InterfaceType rawType = classElement.type;
6183 InterfaceType fullType = 6187 InterfaceType fullType =
6184 rawType.substitute2(targs, rawType.typeArguments); 6188 rawType.substitute2(targs, rawType.typeArguments);
6185 // The element resolver uses the type on the constructor name, so 6189 // The element resolver uses the type on the constructor name, so
6186 // infer it first 6190 // infer it first
6187 typeAnalyzer.inferConstructorName(node.constructorName, fullType); 6191 typeAnalyzer.inferConstructorName(node.constructorName, fullType);
6188 break; 6192 break;
6189 } 6193 }
6190 } 6194 }
6191 } 6195 }
6192 } 6196 }
6193 node.constructorName?.accept(this); 6197 node.constructorName?.accept(this);
6194 FunctionType constructorType = node.constructorName.staticElement?.type; 6198 FunctionType constructorType =
6199 staticElementForConstructorReference(node.constructorName)?.type;
6195 if (constructorType != null) { 6200 if (constructorType != null) {
6196 InferenceContext.setType(node.argumentList, constructorType); 6201 InferenceContext.setType(node.argumentList, constructorType);
6197 } 6202 }
6198 node.argumentList?.accept(this); 6203 node.argumentList?.accept(this);
6199 node.accept(elementResolver); 6204 node.accept(elementResolver);
6200 node.accept(typeAnalyzer); 6205 node.accept(typeAnalyzer);
6201 return null; 6206 return null;
6202 } 6207 }
6203 6208
6204 @override 6209 @override
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
6343 } 6348 }
6344 6349
6345 @override 6350 @override
6346 Object visitRedirectingConstructorInvocation( 6351 Object visitRedirectingConstructorInvocation(
6347 RedirectingConstructorInvocation node) { 6352 RedirectingConstructorInvocation node) {
6348 // 6353 //
6349 // We visit the argument list, but do not visit the optional identifier 6354 // We visit the argument list, but do not visit the optional identifier
6350 // because it needs to be visited in the context of the constructor 6355 // because it needs to be visited in the context of the constructor
6351 // invocation. 6356 // invocation.
6352 // 6357 //
6353 InferenceContext.setType(node.argumentList, node.staticElement?.type); 6358 InferenceContext.setType(
6359 node.argumentList, staticElementForConstructorReference(node)?.type);
6354 node.argumentList?.accept(this); 6360 node.argumentList?.accept(this);
6355 node.accept(elementResolver); 6361 node.accept(elementResolver);
6356 node.accept(typeAnalyzer); 6362 node.accept(typeAnalyzer);
6357 return null; 6363 return null;
6358 } 6364 }
6359 6365
6360 @override 6366 @override
6361 Object visitReturnStatement(ReturnStatement node) { 6367 Object visitReturnStatement(ReturnStatement node) {
6362 Expression e = node.expression; 6368 Expression e = node.expression;
6363 InferenceContext.setType(e, inferenceContext.returnContext); 6369 InferenceContext.setType(e, inferenceContext.returnContext);
(...skipping 13 matching lines...) Expand all
6377 @override 6383 @override
6378 Object visitShowCombinator(ShowCombinator node) => null; 6384 Object visitShowCombinator(ShowCombinator node) => null;
6379 6385
6380 @override 6386 @override
6381 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 6387 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
6382 // 6388 //
6383 // We visit the argument list, but do not visit the optional identifier 6389 // We visit the argument list, but do not visit the optional identifier
6384 // because it needs to be visited in the context of the constructor 6390 // because it needs to be visited in the context of the constructor
6385 // invocation. 6391 // invocation.
6386 // 6392 //
6387 InferenceContext.setType(node.argumentList, node.staticElement?.type); 6393 InferenceContext.setType(
6394 node.argumentList, staticElementForConstructorReference(node)?.type);
6388 node.argumentList?.accept(this); 6395 node.argumentList?.accept(this);
6389 node.accept(elementResolver); 6396 node.accept(elementResolver);
6390 node.accept(typeAnalyzer); 6397 node.accept(typeAnalyzer);
6391 return null; 6398 return null;
6392 } 6399 }
6393 6400
6394 @override 6401 @override
6395 Object visitSwitchCase(SwitchCase node) { 6402 Object visitSwitchCase(SwitchCase node) {
6396 _overrideManager.enterScope(); 6403 _overrideManager.enterScope();
6397 try { 6404 try {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
6450 node.initializer != null) { 6457 node.initializer != null) {
6451 (element as ConstVariableElement).constantInitializer = 6458 (element as ConstVariableElement).constantInitializer =
6452 new ConstantAstCloner().cloneNode(node.initializer); 6459 new ConstantAstCloner().cloneNode(node.initializer);
6453 } 6460 }
6454 return null; 6461 return null;
6455 } 6462 }
6456 6463
6457 @override 6464 @override
6458 visitVariableDeclarationList(VariableDeclarationList node) { 6465 visitVariableDeclarationList(VariableDeclarationList node) {
6459 for (VariableDeclaration decl in node.variables) { 6466 for (VariableDeclaration decl in node.variables) {
6460 InferenceContext.setType(decl, decl.element?.type); 6467 VariableElement variableElement = elementForVariableDeclaration(decl);
6468 InferenceContext.setType(decl, variableElement?.type);
6461 } 6469 }
6462 super.visitVariableDeclarationList(node); 6470 super.visitVariableDeclarationList(node);
6463 } 6471 }
6464 6472
6465 @override 6473 @override
6466 Object visitWhileStatement(WhileStatement node) { 6474 Object visitWhileStatement(WhileStatement node) {
6467 // Note: since we don't call the base class, we have to maintain 6475 // Note: since we don't call the base class, we have to maintain
6468 // _implicitLabelScope ourselves. 6476 // _implicitLabelScope ourselves.
6469 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; 6477 ImplicitLabelScope outerImplicitScope = _implicitLabelScope;
6470 try { 6478 try {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
6737 return; 6745 return;
6738 } 6746 }
6739 FunctionExpression closure = mayBeClosure as FunctionExpression; 6747 FunctionExpression closure = mayBeClosure as FunctionExpression;
6740 // prepare expected closure type 6748 // prepare expected closure type
6741 if (mayByFunctionType is! FunctionType) { 6749 if (mayByFunctionType is! FunctionType) {
6742 return; 6750 return;
6743 } 6751 }
6744 FunctionType expectedClosureType = mayByFunctionType as FunctionType; 6752 FunctionType expectedClosureType = mayByFunctionType as FunctionType;
6745 // If the expectedClosureType is not more specific than the static type, 6753 // If the expectedClosureType is not more specific than the static type,
6746 // return. 6754 // return.
6747 DartType staticClosureType = closure.element?.type; 6755 DartType staticClosureType = elementForFunctionExpression(closure)?.type;
6748 if (staticClosureType != null && 6756 if (staticClosureType != null &&
6749 !FunctionTypeImpl.relate( 6757 !FunctionTypeImpl.relate(
6750 expectedClosureType, 6758 expectedClosureType,
6751 staticClosureType, 6759 staticClosureType,
6752 (DartType t, DartType s, _, __) => 6760 (DartType t, DartType s, _, __) =>
6753 (t as TypeImpl).isMoreSpecificThan(s), 6761 (t as TypeImpl).isMoreSpecificThan(s),
6754 new TypeSystemImpl().instantiateToBounds, 6762 new TypeSystemImpl().instantiateToBounds,
6755 returnRelation: (s, t) => true)) { 6763 returnRelation: (s, t) => true)) {
6756 return; 6764 return;
6757 } 6765 }
(...skipping 4004 matching lines...) Expand 10 before | Expand all | Expand 10 after
10762 return null; 10770 return null;
10763 } 10771 }
10764 if (identical(node.staticElement, variable)) { 10772 if (identical(node.staticElement, variable)) {
10765 if (node.inSetterContext()) { 10773 if (node.inSetterContext()) {
10766 result = true; 10774 result = true;
10767 } 10775 }
10768 } 10776 }
10769 return null; 10777 return null;
10770 } 10778 }
10771 } 10779 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698