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

Unified Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 2225413002: fix #26139, allow inferring a more precise return type (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: add comment Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/context/mock_sdk.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 4a70c667c78425be69ed028fa4618aa25b3be919..017f2e394021b78b2117fe04c646ba97cc3d38fa 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -4719,12 +4719,9 @@ class InferenceContext {
if (_returnStack.isEmpty) {
return;
}
- DartType context = _returnStack.last;
- if (context == null || context.isDynamic) {
- DartType inferred = _inferredReturn.last;
- inferred = _typeSystem.getLeastUpperBound(_typeProvider, type, inferred);
- _inferredReturn[_inferredReturn.length - 1] = inferred;
- }
+ DartType inferred = _inferredReturn.last;
+ inferred = _typeSystem.getLeastUpperBound(_typeProvider, type, inferred);
+ _inferredReturn[_inferredReturn.length - 1] = inferred;
}
/**
@@ -4746,15 +4743,14 @@ class InferenceContext {
* bound of all types added with [addReturnOrYieldType].
*/
void popReturnContext(BlockFunctionBody node) {
- assert(_returnStack.isNotEmpty && _inferredReturn.isNotEmpty);
- if (_returnStack.isNotEmpty) {
- _returnStack.removeLast();
- }
- if (_inferredReturn.isNotEmpty) {
+ if (_returnStack.isNotEmpty && _inferredReturn.isNotEmpty) {
+ DartType context = _returnStack.removeLast() ?? DynamicTypeImpl.instance;
DartType inferred = _inferredReturn.removeLast();
- if (!inferred.isBottom) {
+ if (!inferred.isBottom && _typeSystem.isSubtypeOf(inferred, context)) {
setType(node, inferred);
}
+ } else {
+ assert(false);
}
}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/context/mock_sdk.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698