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

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: Avoid merge conflict 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 4784 matching lines...) Expand 10 before | Expand all | Expand 10 after
9023 * Return the type representing 'Future<dynamic>'. 9020 * Return the type representing 'Future<dynamic>'.
9024 */ 9021 */
9025 InterfaceType get futureDynamicType; 9022 InterfaceType get futureDynamicType;
9026 9023
9027 /** 9024 /**
9028 * Return the type representing 'Future<Null>'. 9025 * Return the type representing 'Future<Null>'.
9029 */ 9026 */
9030 InterfaceType get futureNullType; 9027 InterfaceType get futureNullType;
9031 9028
9032 /** 9029 /**
9030 * Return the type representing 'FutureOr<Null>'.
9031 */
9032 InterfaceType get futureOrNullType;
9033
9034 /**
9033 * Return the type representing the built-in type 'FutureOr'. 9035 * Return the type representing the built-in type 'FutureOr'.
9034 */ 9036 */
9035 InterfaceType get futureOrType; 9037 InterfaceType get futureOrType;
9036 9038
9037 /** 9039 /**
9038 * Return the type representing the built-in type 'Future'. 9040 * Return the type representing the built-in type 'Future'.
9039 */ 9041 */
9040 InterfaceType get futureType; 9042 InterfaceType get futureType;
9041 9043
9042 /** 9044 /**
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
9216 * The type representing 'Future<dynamic>'. 9218 * The type representing 'Future<dynamic>'.
9217 */ 9219 */
9218 InterfaceType _futureDynamicType; 9220 InterfaceType _futureDynamicType;
9219 9221
9220 /** 9222 /**
9221 * The type representing 'Future<Null>'. 9223 * The type representing 'Future<Null>'.
9222 */ 9224 */
9223 InterfaceType _futureNullType; 9225 InterfaceType _futureNullType;
9224 9226
9225 /** 9227 /**
9228 * The type representing 'FutureOr<Null>'.
9229 */
9230 InterfaceType _futureOrNullType;
9231
9232 /**
9226 * The type representing the built-in type 'FutureOr'. 9233 * The type representing the built-in type 'FutureOr'.
9227 */ 9234 */
9228 InterfaceType _futureOrType; 9235 InterfaceType _futureOrType;
9229 9236
9230 /** 9237 /**
9231 * The type representing the built-in type 'Future'. 9238 * The type representing the built-in type 'Future'.
9232 */ 9239 */
9233 InterfaceType _futureType; 9240 InterfaceType _futureType;
9234 9241
9235 /** 9242 /**
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
9351 @override 9358 @override
9352 InterfaceType get functionType => _functionType; 9359 InterfaceType get functionType => _functionType;
9353 9360
9354 @override 9361 @override
9355 InterfaceType get futureDynamicType => _futureDynamicType; 9362 InterfaceType get futureDynamicType => _futureDynamicType;
9356 9363
9357 @override 9364 @override
9358 InterfaceType get futureNullType => _futureNullType; 9365 InterfaceType get futureNullType => _futureNullType;
9359 9366
9360 @override 9367 @override
9368 InterfaceType get futureOrNullType => _futureOrNullType;
9369
9370 @override
9361 InterfaceType get futureOrType => _futureOrType; 9371 InterfaceType get futureOrType => _futureOrType;
9362 9372
9363 @override 9373 @override
9364 InterfaceType get futureType => _futureType; 9374 InterfaceType get futureType => _futureType;
9365 9375
9366 @override 9376 @override
9367 InterfaceType get intType => _intType; 9377 InterfaceType get intType => _intType;
9368 9378
9369 @override 9379 @override
9370 InterfaceType get iterableDynamicType => _iterableDynamicType; 9380 InterfaceType get iterableDynamicType => _iterableDynamicType;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
9455 _numType = _getType(coreNamespace, "num"); 9465 _numType = _getType(coreNamespace, "num");
9456 _objectType = _getType(coreNamespace, "Object"); 9466 _objectType = _getType(coreNamespace, "Object");
9457 _stackTraceType = _getType(coreNamespace, "StackTrace"); 9467 _stackTraceType = _getType(coreNamespace, "StackTrace");
9458 _streamType = _getType(asyncNamespace, "Stream"); 9468 _streamType = _getType(asyncNamespace, "Stream");
9459 _stringType = _getType(coreNamespace, "String"); 9469 _stringType = _getType(coreNamespace, "String");
9460 _symbolType = _getType(coreNamespace, "Symbol"); 9470 _symbolType = _getType(coreNamespace, "Symbol");
9461 _typeType = _getType(coreNamespace, "Type"); 9471 _typeType = _getType(coreNamespace, "Type");
9462 _undefinedType = UndefinedTypeImpl.instance; 9472 _undefinedType = UndefinedTypeImpl.instance;
9463 _futureDynamicType = _futureType.instantiate(<DartType>[_dynamicType]); 9473 _futureDynamicType = _futureType.instantiate(<DartType>[_dynamicType]);
9464 _futureNullType = _futureType.instantiate(<DartType>[_nullType]); 9474 _futureNullType = _futureType.instantiate(<DartType>[_nullType]);
9475 _futureOrNullType = _futureOrType.instantiate(<DartType>[_nullType]);
9465 _iterableDynamicType = _iterableType.instantiate(<DartType>[_dynamicType]); 9476 _iterableDynamicType = _iterableType.instantiate(<DartType>[_dynamicType]);
9466 _streamDynamicType = _streamType.instantiate(<DartType>[_dynamicType]); 9477 _streamDynamicType = _streamType.instantiate(<DartType>[_dynamicType]);
9467 // FutureOr<T> is still fairly new, so if we're analyzing an SDK that 9478 // FutureOr<T> is still fairly new, so if we're analyzing an SDK that
9468 // doesn't have it yet, create an element for it. 9479 // doesn't have it yet, create an element for it.
9469 _futureOrType ??= createPlaceholderFutureOr(_futureType, _objectType); 9480 _futureOrType ??= createPlaceholderFutureOr(_futureType, _objectType);
9470 } 9481 }
9471 9482
9472 /** 9483 /**
9473 * Create an [InterfaceType] that can be used for `FutureOr<T>` if the SDK 9484 * Create an [InterfaceType] that can be used for `FutureOr<T>` if the SDK
9474 * being analyzed does not contain its own `FutureOr<T>`. This ensures that 9485 * being analyzed does not contain its own `FutureOr<T>`. This ensures that
(...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after
10851 return null; 10862 return null;
10852 } 10863 }
10853 if (identical(node.staticElement, variable)) { 10864 if (identical(node.staticElement, variable)) {
10854 if (node.inSetterContext()) { 10865 if (node.inSetterContext()) {
10855 result = true; 10866 result = true;
10856 } 10867 }
10857 } 10868 }
10858 return null; 10869 return null;
10859 } 10870 }
10860 } 10871 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698