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

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

Issue 1649523002: fixes inferring () -> <bottom> in strong mode (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merged Created 4 years, 11 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/task/strong/inferred_type_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/static_type_analyzer.dart
diff --git a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
index 62decdc72d05eb9ec35bd1d7d17afae86560573e..aacdabeb17e27fa726dd9f2fb795b7089e44a727 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -466,10 +466,19 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
node.element as ExecutableElementImpl;
DartType computedType = _computeStaticReturnTypeOfFunctionExpression(node);
if (_strongMode) {
+ // In strong mode, we don't want to allow the function's return type to
+ // be bottom. If the surrounding context has a more precise type, we
+ // will push it down with inference, below. If not we want to use dynamic.
+ // TODO(jmesserly): should we do this for the `null` literal always in
+ // strong mode, instead of handling it here?
+ if (computedType.isBottom) {
+ computedType = DynamicTypeImpl.instance;
+ }
+
DartType functionType = InferenceContext.getType(node);
if (functionType is FunctionType) {
DartType returnType = functionType.returnType;
- if ((computedType.isDynamic || computedType.isBottom) &&
+ if (computedType.isDynamic &&
!(returnType.isDynamic || returnType.isBottom)) {
computedType = returnType;
_resolver.inferenceContext.recordInference(node, functionType);
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698