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

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

Issue 2145273002: fix propagated type of lambdas in strong mode (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 months 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
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/static_type_analyzer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 5640 matching lines...) Expand 10 before | Expand all | Expand 10 after
5651 * be built and the comment resolved. 5651 * be built and the comment resolved.
5652 */ 5652 */
5653 bool resolveOnlyCommentInFunctionBody = false; 5653 bool resolveOnlyCommentInFunctionBody = false;
5654 5654
5655 /** 5655 /**
5656 * Body of the function currently being analyzed, if any. 5656 * Body of the function currently being analyzed, if any.
5657 */ 5657 */
5658 FunctionBody _currentFunctionBody; 5658 FunctionBody _currentFunctionBody;
5659 5659
5660 /** 5660 /**
5661 * Are we running in strong mode or not.
5662 */
5663 bool strongMode;
5664
5665 /**
5661 * Initialize a newly created visitor to resolve the nodes in an AST node. 5666 * Initialize a newly created visitor to resolve the nodes in an AST node.
5662 * 5667 *
5663 * The [definingLibrary] is the element for the library containing the node 5668 * The [definingLibrary] is the element for the library containing the node
5664 * being visited. The [source] is the source representing the compilation unit 5669 * being visited. The [source] is the source representing the compilation unit
5665 * containing the node being visited. The [typeProvider] is the object used to 5670 * containing the node being visited. The [typeProvider] is the object used to
5666 * access the types from the core library. The [errorListener] is the error 5671 * access the types from the core library. The [errorListener] is the error
5667 * listener that will be informed of any errors that are found during 5672 * listener that will be informed of any errors that are found during
5668 * resolution. The [nameScope] is the scope used to resolve identifiers in the 5673 * resolution. The [nameScope] is the scope used to resolve identifiers in the
5669 * node that will first be visited. If `null` or unspecified, a new 5674 * node that will first be visited. If `null` or unspecified, a new
5670 * [LibraryScope] will be created based on [definingLibrary] and 5675 * [LibraryScope] will be created based on [definingLibrary] and
5671 * [typeProvider]. The [inheritanceManager] is used to perform inheritance 5676 * [typeProvider]. The [inheritanceManager] is used to perform inheritance
5672 * lookups. If `null` or unspecified, a new [InheritanceManager] will be 5677 * lookups. If `null` or unspecified, a new [InheritanceManager] will be
5673 * created based on [definingLibrary]. The [typeAnalyzerFactory] is used to 5678 * created based on [definingLibrary]. The [typeAnalyzerFactory] is used to
5674 * create the type analyzer. If `null` or unspecified, a type analyzer of 5679 * create the type analyzer. If `null` or unspecified, a type analyzer of
5675 * type [StaticTypeAnalyzer] will be created. 5680 * type [StaticTypeAnalyzer] will be created.
5676 */ 5681 */
5677 ResolverVisitor(LibraryElement definingLibrary, Source source, 5682 ResolverVisitor(LibraryElement definingLibrary, Source source,
5678 TypeProvider typeProvider, AnalysisErrorListener errorListener, 5683 TypeProvider typeProvider, AnalysisErrorListener errorListener,
5679 {Scope nameScope}) 5684 {Scope nameScope})
5680 : super(definingLibrary, source, typeProvider, errorListener, 5685 : super(definingLibrary, source, typeProvider, errorListener,
5681 nameScope: nameScope) { 5686 nameScope: nameScope) {
5687 AnalysisOptions options = definingLibrary.context.analysisOptions;
5688 this.strongMode = options.strongMode;
5682 this.elementResolver = new ElementResolver(this); 5689 this.elementResolver = new ElementResolver(this);
5683 this.typeSystem = definingLibrary.context.typeSystem; 5690 this.typeSystem = definingLibrary.context.typeSystem;
5684 bool strongModeHints = false; 5691 bool strongModeHints = false;
5685 AnalysisOptions options = definingLibrary.context.analysisOptions;
5686 if (options is AnalysisOptionsImpl) { 5692 if (options is AnalysisOptionsImpl) {
5687 strongModeHints = options.strongModeHints; 5693 strongModeHints = options.strongModeHints;
5688 } 5694 }
5689 this.inferenceContext = new InferenceContext._( 5695 this.inferenceContext = new InferenceContext._(
5690 errorReporter, typeProvider, typeSystem, strongModeHints); 5696 errorReporter, typeProvider, typeSystem, strongModeHints);
5691 this.typeAnalyzer = new StaticTypeAnalyzer(this); 5697 this.typeAnalyzer = new StaticTypeAnalyzer(this);
5692 } 5698 }
5693 5699
5694 /** 5700 /**
5695 * Return the element representing the function containing the current node, o r `null` if 5701 * Return the element representing the function containing the current node, o r `null` if
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
6614 _currentFunctionBody = outerFunctionBody; 6620 _currentFunctionBody = outerFunctionBody;
6615 _enclosingFunction = outerFunction; 6621 _enclosingFunction = outerFunction;
6616 } 6622 }
6617 return null; 6623 return null;
6618 } 6624 }
6619 6625
6620 @override 6626 @override
6621 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { 6627 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
6622 node.function?.accept(this); 6628 node.function?.accept(this);
6623 node.accept(elementResolver); 6629 node.accept(elementResolver);
6624 _inferFunctionExpressionsParametersTypes(node.argumentList);
6625 _inferArgumentTypesFromContext(node); 6630 _inferArgumentTypesFromContext(node);
6626 node.argumentList?.accept(this); 6631 node.argumentList?.accept(this);
6627 node.accept(typeAnalyzer); 6632 node.accept(typeAnalyzer);
6628 return null; 6633 return null;
6629 } 6634 }
6630 6635
6631 @override 6636 @override
6632 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 6637 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
6633 // Resolve the metadata in the library scope. 6638 // Resolve the metadata in the library scope.
6634 if (node.metadata != null) { 6639 if (node.metadata != null) {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
6841 6846
6842 @override 6847 @override
6843 Object visitMethodInvocation(MethodInvocation node) { 6848 Object visitMethodInvocation(MethodInvocation node) {
6844 // 6849 //
6845 // We visit the target and argument list, but do not visit the method name 6850 // We visit the target and argument list, but do not visit the method name
6846 // because it needs to be visited in the context of the invocation. 6851 // because it needs to be visited in the context of the invocation.
6847 // 6852 //
6848 node.target?.accept(this); 6853 node.target?.accept(this);
6849 node.typeArguments?.accept(this); 6854 node.typeArguments?.accept(this);
6850 node.accept(elementResolver); 6855 node.accept(elementResolver);
6851 _inferFunctionExpressionsParametersTypes(node.argumentList);
6852 _inferArgumentTypesFromContext(node); 6856 _inferArgumentTypesFromContext(node);
6853 node.argumentList?.accept(this); 6857 node.argumentList?.accept(this);
6854 node.accept(typeAnalyzer); 6858 node.accept(typeAnalyzer);
6855 return null; 6859 return null;
6856 } 6860 }
6857 6861
6858 @override 6862 @override
6859 Object visitNamedExpression(NamedExpression node) { 6863 Object visitNamedExpression(NamedExpression node) {
6860 InferenceContext.setType(node.expression, InferenceContext.getType(node)); 6864 InferenceContext.setType(node.expression, InferenceContext.getType(node));
6861 return super.visitNamedExpression(node); 6865 return super.visitNamedExpression(node);
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
7204 if (onDataParameters == null || onDataParameters.isEmpty) { 7208 if (onDataParameters == null || onDataParameters.isEmpty) {
7205 return null; 7209 return null;
7206 } 7210 }
7207 return onDataParameters[0].type; 7211 return onDataParameters[0].type;
7208 } 7212 }
7209 } 7213 }
7210 return null; 7214 return null;
7211 } 7215 }
7212 7216
7213 void _inferArgumentTypesFromContext(InvocationExpression node) { 7217 void _inferArgumentTypesFromContext(InvocationExpression node) {
7218 if (!strongMode) {
7219 // Use propagated type inference for lambdas if not in strong mode.
7220 _inferFunctionExpressionsParametersTypes(node.argumentList);
7221 return;
7222 }
7223
7214 DartType contextType = node.staticInvokeType; 7224 DartType contextType = node.staticInvokeType;
7215 if (contextType is FunctionType) { 7225 if (contextType is FunctionType) {
7216 DartType originalType = node.function.staticType; 7226 DartType originalType = node.function.staticType;
7217 DartType returnContextType = InferenceContext.getType(node); 7227 DartType returnContextType = InferenceContext.getType(node);
7218 TypeSystem ts = typeSystem; 7228 TypeSystem ts = typeSystem;
7219 if (returnContextType != null && 7229 if (returnContextType != null &&
7220 node.typeArguments == null && 7230 node.typeArguments == null &&
7221 originalType is FunctionType && 7231 originalType is FunctionType &&
7222 originalType.typeFormals.isNotEmpty && 7232 originalType.typeFormals.isNotEmpty &&
7223 ts is StrongTypeSystemImpl) { 7233 ts is StrongTypeSystemImpl) {
(...skipping 3826 matching lines...) Expand 10 before | Expand all | Expand 10 after
11050 return null; 11060 return null;
11051 } 11061 }
11052 if (identical(node.staticElement, variable)) { 11062 if (identical(node.staticElement, variable)) {
11053 if (node.inSetterContext()) { 11063 if (node.inSetterContext()) {
11054 result = true; 11064 result = true;
11055 } 11065 }
11056 } 11066 }
11057 return null; 11067 return null;
11058 } 11068 }
11059 } 11069 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/static_type_analyzer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698