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

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

Issue 1513603002: fix #25182, downwards inference for calls to fields/getters/vars/params/locals (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.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 engine.resolver; 5 library engine.resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import '../task/strong/info.dart' show InferredType, StaticInfo; 9 import '../task/strong/info.dart' show InferredType, StaticInfo;
10 import 'ast.dart'; 10 import 'ast.dart';
(...skipping 8995 matching lines...) Expand 10 before | Expand all | Expand 10 after
9006 Object visitListLiteral(ListLiteral node) { 9006 Object visitListLiteral(ListLiteral node) {
9007 DartType contextType = InferenceContext.getType(node); 9007 DartType contextType = InferenceContext.getType(node);
9008 List<DartType> targs = null; 9008 List<DartType> targs = null;
9009 if (node.typeArguments != null) { 9009 if (node.typeArguments != null) {
9010 targs = node.typeArguments.arguments.map((t) => t.type).toList(); 9010 targs = node.typeArguments.arguments.map((t) => t.type).toList();
9011 } else if (contextType is InterfaceType) { 9011 } else if (contextType is InterfaceType) {
9012 InterfaceType listD = 9012 InterfaceType listD =
9013 typeProvider.listType.substitute4([typeProvider.dynamicType]); 9013 typeProvider.listType.substitute4([typeProvider.dynamicType]);
9014 targs = inferenceContext.matchTypes(listD, contextType); 9014 targs = inferenceContext.matchTypes(listD, contextType);
9015 } 9015 }
9016 if (targs != null && 9016 if (targs != null && targs.length == 1 && !targs[0].isDynamic) {
9017 targs.length == 1 &&
9018 !targs[0].isDynamic) {
9019 DartType eType = targs[0]; 9017 DartType eType = targs[0];
9020 InterfaceType listT = typeProvider.listType.substitute4([eType]); 9018 InterfaceType listT = typeProvider.listType.substitute4([eType]);
9021 for (Expression child in node.elements) { 9019 for (Expression child in node.elements) {
9022 InferenceContext.setType(child, eType); 9020 InferenceContext.setType(child, eType);
9023 } 9021 }
9024 InferenceContext.setType(node, listT); 9022 InferenceContext.setType(node, listT);
9025 } else { 9023 } else {
9026 InferenceContext.clearType(node); 9024 InferenceContext.clearType(node);
9027 } 9025 }
9028 super.visitListLiteral(node); 9026 super.visitListLiteral(node);
9029 return null; 9027 return null;
9030 } 9028 }
9031 9029
9032 @override 9030 @override
9033 Object visitMapLiteral(MapLiteral node) { 9031 Object visitMapLiteral(MapLiteral node) {
9034 DartType contextType = InferenceContext.getType(node); 9032 DartType contextType = InferenceContext.getType(node);
9035 List<DartType> targs = null; 9033 List<DartType> targs = null;
9036 if (node.typeArguments != null) { 9034 if (node.typeArguments != null) {
9037 targs = node.typeArguments.arguments.map((t) => t.type).toList(); 9035 targs = node.typeArguments.arguments.map((t) => t.type).toList();
9038 } else if (contextType is InterfaceType) { 9036 } else if (contextType is InterfaceType) {
9039 InterfaceType mapD = typeProvider.mapType 9037 InterfaceType mapD = typeProvider.mapType
9040 .substitute4([typeProvider.dynamicType, typeProvider.dynamicType]); 9038 .substitute4([typeProvider.dynamicType, typeProvider.dynamicType]);
9041 targs = inferenceContext.matchTypes(mapD, contextType); 9039 targs = inferenceContext.matchTypes(mapD, contextType);
9042 } 9040 }
9043 if (targs != null && 9041 if (targs != null && targs.length == 2 && targs.any((t) => !t.isDynamic)) {
9044 targs.length == 2 &&
9045 targs.any((t) => !t.isDynamic)) {
9046 DartType kType = targs[0]; 9042 DartType kType = targs[0];
9047 DartType vType = targs[1]; 9043 DartType vType = targs[1];
9048 InterfaceType mapT = typeProvider.mapType.substitute4([kType, vType]); 9044 InterfaceType mapT = typeProvider.mapType.substitute4([kType, vType]);
9049 for (MapLiteralEntry entry in node.entries) { 9045 for (MapLiteralEntry entry in node.entries) {
9050 InferenceContext.setType(entry.key, kType); 9046 InferenceContext.setType(entry.key, kType);
9051 InferenceContext.setType(entry.value, vType); 9047 InferenceContext.setType(entry.value, vType);
9052 } 9048 }
9053 InferenceContext.setType(node, mapT); 9049 InferenceContext.setType(node, mapT);
9054 } else { 9050 } else {
9055 InferenceContext.clearType(node); 9051 InferenceContext.clearType(node);
(...skipping 19 matching lines...) Expand all
9075 Object visitMethodInvocation(MethodInvocation node) { 9071 Object visitMethodInvocation(MethodInvocation node) {
9076 // 9072 //
9077 // We visit the target and argument list, but do not visit the method name 9073 // We visit the target and argument list, but do not visit the method name
9078 // because it needs to be visited in the context of the invocation. 9074 // because it needs to be visited in the context of the invocation.
9079 // 9075 //
9080 safelyVisit(node.target); 9076 safelyVisit(node.target);
9081 safelyVisit(node.typeArguments); 9077 safelyVisit(node.typeArguments);
9082 node.accept(elementResolver); 9078 node.accept(elementResolver);
9083 _inferFunctionExpressionsParametersTypes(node.argumentList); 9079 _inferFunctionExpressionsParametersTypes(node.argumentList);
9084 Element methodElement = node.methodName.staticElement; 9080 Element methodElement = node.methodName.staticElement;
9085 if (methodElement is ExecutableElement) { 9081 DartType contextType = null;
9086 InferenceContext.setType(node.argumentList, methodElement.type); 9082 if (methodElement is PropertyAccessorElement && methodElement.isGetter) {
9083 contextType = methodElement.returnType;
9084 } else if (methodElement is VariableElement) {
9085 contextType = methodElement.type;
9086 } else if (methodElement is ExecutableElement) {
9087 contextType = methodElement.type;
9088 }
9089 if (contextType is FunctionType) {
9090 InferenceContext.setType(node.argumentList, contextType);
9087 } 9091 }
9088 safelyVisit(node.argumentList); 9092 safelyVisit(node.argumentList);
9089 node.accept(typeAnalyzer); 9093 node.accept(typeAnalyzer);
9090 return null; 9094 return null;
9091 } 9095 }
9092 9096
9093 @override 9097 @override
9094 Object visitNamedExpression(NamedExpression node) { 9098 Object visitNamedExpression(NamedExpression node) {
9095 InferenceContext.setType(node.expression, InferenceContext.getType(node)); 9099 InferenceContext.setType(node.expression, InferenceContext.getType(node));
9096 return super.visitNamedExpression(node); 9100 return super.visitNamedExpression(node);
(...skipping 4215 matching lines...) Expand 10 before | Expand all | Expand 10 after
13312 nonFields.add(node); 13316 nonFields.add(node);
13313 return null; 13317 return null;
13314 } 13318 }
13315 13319
13316 @override 13320 @override
13317 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 13321 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
13318 13322
13319 @override 13323 @override
13320 Object visitWithClause(WithClause node) => null; 13324 Object visitWithClause(WithClause node) => null;
13321 } 13325 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698