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

Unified Diff: lib/src/checker/resolver.dart

Issue 997143003: Fix for conditional expressions (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Add test case Created 5 years, 9 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 | test/checker/checker_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/checker/resolver.dart
diff --git a/lib/src/checker/resolver.dart b/lib/src/checker/resolver.dart
index c31a1d72abf741d2bae2f38824996938a2de116d..944c69b8e897d627daebedaa9fab74d00f992874 100644
--- a/lib/src/checker/resolver.dart
+++ b/lib/src/checker/resolver.dart
@@ -396,10 +396,28 @@ class RestrictedStaticTypeAnalyzer extends StaticTypeAnalyzer {
}
}
+ @override
+ visitConditionalExpression(ConditionalExpression node) {
+ // TODO(vsm): The static type of a conditional should be the LUB of the
+ // then and else expressions. The analyzer appears to compute dynamic when
+ // one or the other is the null literal. Remove this fix once the
+ // corresponding analyzer bug is fixed:
+ // https://code.google.com/p/dart/issues/detail?id=22854
+ super.visitConditionalExpression(node);
+ if (node.staticType.isDynamic) {
+ var thenExpr = node.thenExpression;
+ var elseExpr = node.elseExpression;
+ if (thenExpr.staticType.isBottom) {
+ node.staticType = elseExpr.staticType;
+ } else if (elseExpr.staticType.isBottom) {
+ node.staticType = thenExpr.staticType;
+ }
+ }
+ }
+
// Review note: no longer need to override visitFunctionExpression, this is
// handled by the analyzer internally.
// TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result?
- // TODO(vsm): in visitConditionalExpression: check... LUB in rules?
// TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression
// type in a (...) => expr or just the written type?
« no previous file with comments | « no previous file | test/checker/checker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698