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

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

Issue 2655273008: fix #28526 and fix #28527 FutureOr<T> in await and subtype (Closed)
Patch Set: fix Created 3 years, 10 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
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.static_type_analyzer; 5 library analyzer.src.generated.static_type_analyzer;
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/standard_resolution_map.dart'; 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 271 }
272 272
273 /** 273 /**
274 * The Dart Language Specification, 16.29 (Await Expressions): 274 * The Dart Language Specification, 16.29 (Await Expressions):
275 * 275 *
276 * The static type of [the expression "await e"] is flatten(T) where T is 276 * The static type of [the expression "await e"] is flatten(T) where T is
277 * the static type of e. 277 * the static type of e.
278 */ 278 */
279 @override 279 @override
280 Object visitAwaitExpression(AwaitExpression node) { 280 Object visitAwaitExpression(AwaitExpression node) {
281 DartType staticExpressionType = _getStaticType(node.expression); 281 // Await the Future. This results in whatever type is (ultimately) returned.
282 if (staticExpressionType == null) { 282 DartType awaitType(DartType awaitedType) {
283 // TODO(brianwilkerson) Determine whether this can still happen. 283 if (awaitedType == null) {
284 staticExpressionType = _dynamicType; 284 return null;
285 }
286 if (awaitedType.isDartAsyncFutureOr) {
287 return awaitType((awaitedType as InterfaceType).typeArguments[0]);
288 }
289 return awaitedType.flattenFutures(_typeSystem);
285 } 290 }
286 DartType staticType = staticExpressionType.flattenFutures(_typeSystem); 291
287 _recordStaticType(node, staticType); 292 _recordStaticType(node, awaitType(_getStaticType(node.expression)));
288 DartType propagatedExpressionType = node.expression.propagatedType; 293 DartType propagatedType = awaitType(node.expression.propagatedType);
289 DartType propagatedType =
290 propagatedExpressionType?.flattenFutures(_typeSystem);
291 _resolver.recordPropagatedTypeIfBetter(node, propagatedType); 294 _resolver.recordPropagatedTypeIfBetter(node, propagatedType);
292 return null; 295 return null;
293 } 296 }
294 297
295 /** 298 /**
296 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo gical boolean 299 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo gical boolean
297 * expression is `bool`.</blockquote> 300 * expression is `bool`.</blockquote>
298 * 301 *
299 * The Dart Language Specification, 12.21:<blockquote>A bitwise expression of the form 302 * The Dart Language Specification, 12.21:<blockquote>A bitwise expression of the form
300 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio n 303 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio n
(...skipping 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after
2364 } 2367 }
2365 // merge types 2368 // merge types
2366 if (result == null) { 2369 if (result == null) {
2367 result = type; 2370 result = type;
2368 } else { 2371 } else {
2369 result = _typeSystem.getLeastUpperBound(result, type); 2372 result = _typeSystem.getLeastUpperBound(result, type);
2370 } 2373 }
2371 return null; 2374 return null;
2372 } 2375 }
2373 } 2376 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/type_system.dart » ('j') | pkg/analyzer/lib/src/generated/type_system.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698