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

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

Issue 2667343005: Infer Null for return type of functions with empty returns. (Closed)
Patch Set: Address comments, fix 28630, ddc expectations 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.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/standard_resolution_map.dart'; 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
(...skipping 4190 matching lines...) Expand 10 before | Expand all | Expand 10 after
4201 * Pop a return type off of the return stack. 4201 * Pop a return type off of the return stack.
4202 * 4202 *
4203 * Also record any inferred return type using [setType], unless this node 4203 * Also record any inferred return type using [setType], unless this node
4204 * already has a context type. This recorded type will be the least upper 4204 * already has a context type. This recorded type will be the least upper
4205 * bound of all types added with [addReturnOrYieldType]. 4205 * bound of all types added with [addReturnOrYieldType].
4206 */ 4206 */
4207 void popReturnContext(BlockFunctionBody node) { 4207 void popReturnContext(BlockFunctionBody node) {
4208 if (_returnStack.isNotEmpty && _inferredReturn.isNotEmpty) { 4208 if (_returnStack.isNotEmpty && _inferredReturn.isNotEmpty) {
4209 DartType context = _returnStack.removeLast() ?? DynamicTypeImpl.instance; 4209 DartType context = _returnStack.removeLast() ?? DynamicTypeImpl.instance;
4210 DartType inferred = _inferredReturn.removeLast(); 4210 DartType inferred = _inferredReturn.removeLast();
4211 if (inferred.isBottom || inferred.isDartCoreNull) {
4212 return;
4213 }
4214 4211
4215 if (_typeSystem.isSubtypeOf(inferred, context)) { 4212 if (_typeSystem.isSubtypeOf(inferred, context)) {
4216 setType(node, inferred); 4213 setType(node, inferred);
4217 } 4214 }
4218 } else { 4215 } else {
4219 assert(false); 4216 assert(false);
4220 } 4217 }
4221 } 4218 }
4222 4219
4223 /** 4220 /**
4224 * Push a block function body's return type onto the return stack. 4221 * Push a block function body's return type onto the return stack.
4225 */ 4222 */
4226 void pushReturnContext(BlockFunctionBody node) { 4223 void pushReturnContext(BlockFunctionBody node) {
4227 _returnStack.add(getContext(node)); 4224 _returnStack.add(getContext(node));
4228 _inferredReturn.add(BottomTypeImpl.instance); 4225 _inferredReturn.add(_typeProvider.nullType);
4229 } 4226 }
4230 4227
4231 /** 4228 /**
4232 * Place an info node into the error stream indicating that a 4229 * Place an info node into the error stream indicating that a
4233 * [type] has been inferred as the type of [node]. 4230 * [type] has been inferred as the type of [node].
4234 */ 4231 */
4235 void recordInference(Expression node, DartType type) { 4232 void recordInference(Expression node, DartType type) {
4236 if (!_inferenceHints) { 4233 if (!_inferenceHints) {
4237 return; 4234 return;
4238 } 4235 }
(...skipping 4821 matching lines...) Expand 10 before | Expand all | Expand 10 after
9060 * Return the type representing 'Future<dynamic>'. 9057 * Return the type representing 'Future<dynamic>'.
9061 */ 9058 */
9062 InterfaceType get futureDynamicType; 9059 InterfaceType get futureDynamicType;
9063 9060
9064 /** 9061 /**
9065 * Return the type representing 'Future<Null>'. 9062 * Return the type representing 'Future<Null>'.
9066 */ 9063 */
9067 InterfaceType get futureNullType; 9064 InterfaceType get futureNullType;
9068 9065
9069 /** 9066 /**
9067 * Return the type representing 'FutureOr<Null>'.
9068 */
9069 InterfaceType get futureOrNullType;
9070
9071 /**
9070 * Return the type representing the built-in type 'FutureOr'. 9072 * Return the type representing the built-in type 'FutureOr'.
9071 */ 9073 */
9072 InterfaceType get futureOrType; 9074 InterfaceType get futureOrType;
9073 9075
9074 /** 9076 /**
9075 * Return the type representing the built-in type 'Future'. 9077 * Return the type representing the built-in type 'Future'.
9076 */ 9078 */
9077 InterfaceType get futureType; 9079 InterfaceType get futureType;
9078 9080
9079 /** 9081 /**
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
9253 * The type representing 'Future<dynamic>'. 9255 * The type representing 'Future<dynamic>'.
9254 */ 9256 */
9255 InterfaceType _futureDynamicType; 9257 InterfaceType _futureDynamicType;
9256 9258
9257 /** 9259 /**
9258 * The type representing 'Future<Null>'. 9260 * The type representing 'Future<Null>'.
9259 */ 9261 */
9260 InterfaceType _futureNullType; 9262 InterfaceType _futureNullType;
9261 9263
9262 /** 9264 /**
9265 * The type representing 'FutureOr<Null>'.
9266 */
9267 InterfaceType _futureOrNullType;
9268
9269 /**
9263 * The type representing the built-in type 'FutureOr'. 9270 * The type representing the built-in type 'FutureOr'.
9264 */ 9271 */
9265 InterfaceType _futureOrType; 9272 InterfaceType _futureOrType;
9266 9273
9267 /** 9274 /**
9268 * The type representing the built-in type 'Future'. 9275 * The type representing the built-in type 'Future'.
9269 */ 9276 */
9270 InterfaceType _futureType; 9277 InterfaceType _futureType;
9271 9278
9272 /** 9279 /**
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
9388 @override 9395 @override
9389 InterfaceType get functionType => _functionType; 9396 InterfaceType get functionType => _functionType;
9390 9397
9391 @override 9398 @override
9392 InterfaceType get futureDynamicType => _futureDynamicType; 9399 InterfaceType get futureDynamicType => _futureDynamicType;
9393 9400
9394 @override 9401 @override
9395 InterfaceType get futureNullType => _futureNullType; 9402 InterfaceType get futureNullType => _futureNullType;
9396 9403
9397 @override 9404 @override
9405 InterfaceType get futureOrNullType => _futureOrNullType;
9406
9407 @override
9398 InterfaceType get futureOrType => _futureOrType; 9408 InterfaceType get futureOrType => _futureOrType;
9399 9409
9400 @override 9410 @override
9401 InterfaceType get futureType => _futureType; 9411 InterfaceType get futureType => _futureType;
9402 9412
9403 @override 9413 @override
9404 InterfaceType get intType => _intType; 9414 InterfaceType get intType => _intType;
9405 9415
9406 @override 9416 @override
9407 InterfaceType get iterableDynamicType => _iterableDynamicType; 9417 InterfaceType get iterableDynamicType => _iterableDynamicType;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
9492 _numType = _getType(coreNamespace, "num"); 9502 _numType = _getType(coreNamespace, "num");
9493 _objectType = _getType(coreNamespace, "Object"); 9503 _objectType = _getType(coreNamespace, "Object");
9494 _stackTraceType = _getType(coreNamespace, "StackTrace"); 9504 _stackTraceType = _getType(coreNamespace, "StackTrace");
9495 _streamType = _getType(asyncNamespace, "Stream"); 9505 _streamType = _getType(asyncNamespace, "Stream");
9496 _stringType = _getType(coreNamespace, "String"); 9506 _stringType = _getType(coreNamespace, "String");
9497 _symbolType = _getType(coreNamespace, "Symbol"); 9507 _symbolType = _getType(coreNamespace, "Symbol");
9498 _typeType = _getType(coreNamespace, "Type"); 9508 _typeType = _getType(coreNamespace, "Type");
9499 _undefinedType = UndefinedTypeImpl.instance; 9509 _undefinedType = UndefinedTypeImpl.instance;
9500 _futureDynamicType = _futureType.instantiate(<DartType>[_dynamicType]); 9510 _futureDynamicType = _futureType.instantiate(<DartType>[_dynamicType]);
9501 _futureNullType = _futureType.instantiate(<DartType>[_nullType]); 9511 _futureNullType = _futureType.instantiate(<DartType>[_nullType]);
9512 _futureOrNullType = _futureOrType.instantiate(<DartType>[_nullType]);
Paul Berry 2017/02/07 18:13:03 This line needs to be after line 9517, or a null r
9502 _iterableDynamicType = _iterableType.instantiate(<DartType>[_dynamicType]); 9513 _iterableDynamicType = _iterableType.instantiate(<DartType>[_dynamicType]);
9503 _streamDynamicType = _streamType.instantiate(<DartType>[_dynamicType]); 9514 _streamDynamicType = _streamType.instantiate(<DartType>[_dynamicType]);
9504 // FutureOr<T> is still fairly new, so if we're analyzing an SDK that 9515 // FutureOr<T> is still fairly new, so if we're analyzing an SDK that
9505 // doesn't have it yet, create an element for it. 9516 // doesn't have it yet, create an element for it.
9506 _futureOrType ??= createPlaceholderFutureOr(_futureType, _objectType); 9517 _futureOrType ??= createPlaceholderFutureOr(_futureType, _objectType);
9507 } 9518 }
9508 9519
9509 /** 9520 /**
9510 * Create an [InterfaceType] that can be used for `FutureOr<T>` if the SDK 9521 * Create an [InterfaceType] that can be used for `FutureOr<T>` if the SDK
9511 * being analyzed does not contain its own `FutureOr<T>`. This ensures that 9522 * being analyzed does not contain its own `FutureOr<T>`. This ensures that
(...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after
10888 return null; 10899 return null;
10889 } 10900 }
10890 if (identical(node.staticElement, variable)) { 10901 if (identical(node.staticElement, variable)) {
10891 if (node.inSetterContext()) { 10902 if (node.inSetterContext()) {
10892 result = true; 10903 result = true;
10893 } 10904 }
10894 } 10905 }
10895 return null; 10906 return null;
10896 } 10907 }
10897 } 10908 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698