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

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

Issue 2280023004: fix #27155, do not push down dynamic as context type (Closed)
Patch Set: add test Created 4 years, 3 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/type_system.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 4945 matching lines...) Expand 10 before | Expand all | Expand 10 after
4956 return t.types; 4956 return t.types;
4957 } 4957 }
4958 return <DartType>[t]; 4958 return <DartType>[t];
4959 } 4959 }
4960 4960
4961 /** 4961 /**
4962 * Attach contextual type information [type] to [node] for use during 4962 * Attach contextual type information [type] to [node] for use during
4963 * inference. 4963 * inference.
4964 */ 4964 */
4965 static void setType(AstNode node, DartType type) { 4965 static void setType(AstNode node, DartType type) {
4966 node?.setProperty(_typeProperty, type); 4966 if (type == null || type.isDynamic) {
4967 clearType(node);
4968 } else {
4969 node?.setProperty(_typeProperty, type);
4970 }
4967 } 4971 }
4968 4972
4969 /** 4973 /**
4970 * Attach contextual type information [type] to [node] for use during 4974 * Attach contextual type information [type] to [node] for use during
4971 * inference. 4975 * inference.
4972 */ 4976 */
4973 static void setTypeFromNode(AstNode innerNode, AstNode outerNode) { 4977 static void setTypeFromNode(AstNode innerNode, AstNode outerNode) {
4974 setType(innerNode, getContext(outerNode)); 4978 setType(innerNode, getContext(outerNode));
4975 } 4979 }
4976 } 4980 }
(...skipping 1641 matching lines...) Expand 10 before | Expand all | Expand 10 after
6618 if (isFutureThen(node.staticParameterElement?.enclosingElement)) { 6622 if (isFutureThen(node.staticParameterElement?.enclosingElement)) {
6619 var futureThenType = 6623 var futureThenType =
6620 InferenceContext.getContext(node.parent) as FunctionType; 6624 InferenceContext.getContext(node.parent) as FunctionType;
6621 6625
6622 // Pretend the return type of Future<T>.then<S> first parameter is 6626 // Pretend the return type of Future<T>.then<S> first parameter is
6623 // 6627 //
6624 // T -> (S | Future<S>) 6628 // T -> (S | Future<S>)
6625 // 6629 //
6626 // We can't represent this in Dart so we populate it here during 6630 // We can't represent this in Dart so we populate it here during
6627 // inference. 6631 // inference.
6628 returnType = FutureUnionType.from( 6632 var typeParamS =
6629 futureThenType.returnType, typeProvider, typeSystem); 6633 futureThenType.returnType.flattenFutures(typeSystem);
6634 returnType =
6635 FutureUnionType.from(typeParamS, typeProvider, typeSystem);
6630 } else { 6636 } else {
6631 returnType = _computeReturnOrYieldType(functionType.returnType); 6637 returnType = _computeReturnOrYieldType(functionType.returnType);
6632 } 6638 }
6633 6639
6634 InferenceContext.setType(node.body, returnType); 6640 InferenceContext.setType(node.body, returnType);
6635 } 6641 }
6636 } 6642 }
6637 super.visitFunctionExpression(node); 6643 super.visitFunctionExpression(node);
6638 } finally { 6644 } finally {
6639 _overrideManager.exitScope(); 6645 _overrideManager.exitScope();
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
7178 // If it's async* we expect Stream<T> 7184 // If it's async* we expect Stream<T>
7179 InterfaceType rawType = isAsynchronous 7185 InterfaceType rawType = isAsynchronous
7180 ? typeProvider.streamDynamicType 7186 ? typeProvider.streamDynamicType
7181 : typeProvider.iterableDynamicType; 7187 : typeProvider.iterableDynamicType;
7182 // Match the types to instantiate the type arguments if possible 7188 // Match the types to instantiate the type arguments if possible
7183 List<DartType> typeArgs = 7189 List<DartType> typeArgs =
7184 inferenceContext.matchTypes(rawType, declaredType); 7190 inferenceContext.matchTypes(rawType, declaredType);
7185 return (typeArgs?.length == 1) ? typeArgs[0] : null; 7191 return (typeArgs?.length == 1) ? typeArgs[0] : null;
7186 } 7192 }
7187 // async functions expect `Future<T> | T` 7193 // async functions expect `Future<T> | T`
7188 return new FutureUnionType(declaredType, typeProvider, typeSystem); 7194 var futureTypeParam = declaredType.flattenFutures(typeSystem);
7195 return FutureUnionType.from(futureTypeParam, typeProvider, typeSystem);
7189 } 7196 }
7190 return declaredType; 7197 return declaredType;
7191 } 7198 }
7192 7199
7193 /** 7200 /**
7194 * The given expression is the expression used to compute the iterator for a 7201 * The given expression is the expression used to compute the iterator for a
7195 * for-each statement. Attempt to compute the type of objects that will be 7202 * for-each statement. Attempt to compute the type of objects that will be
7196 * assigned to the loop variable and return that type. Return `null` if the 7203 * assigned to the loop variable and return that type. Return `null` if the
7197 * type could not be determined. The [iteratorExpression] is the expression 7204 * type could not be determined. The [iteratorExpression] is the expression
7198 * that will return the Iterable being iterated over. 7205 * that will return the Iterable being iterated over.
(...skipping 3972 matching lines...) Expand 10 before | Expand all | Expand 10 after
11171 return null; 11178 return null;
11172 } 11179 }
11173 if (identical(node.staticElement, variable)) { 11180 if (identical(node.staticElement, variable)) {
11174 if (node.inSetterContext()) { 11181 if (node.inSetterContext()) {
11175 result = true; 11182 result = true;
11176 } 11183 }
11177 } 11184 }
11178 return null; 11185 return null;
11179 } 11186 }
11180 } 11187 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/type_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698