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

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

Issue 1121993004: Inference through conditional expressions (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Rebase Created 5 years, 7 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 | « lib/runtime/dart/core.js ('k') | 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/rules.dart
diff --git a/lib/src/checker/rules.dart b/lib/src/checker/rules.dart
index bd59410646ab723308a33ba21e734a5eb8551ecd..b406b9f6e930cebe06425f42cc41e4dfa6068ae9 100644
--- a/lib/src/checker/rules.dart
+++ b/lib/src/checker/rules.dart
@@ -610,6 +610,9 @@ class DownwardsInference {
/// Downward inference
bool _inferExpression(Expression e, DartType t, List<String> errors,
{cast: true}) {
+ if (e is ConditionalExpression) {
+ return _inferConditionalExpression(e, t, errors);
+ }
if (e is Conversion) return _inferExpression(e.node, t, errors);
if (rules.isSubTypeOf(rules.getStaticType(e), t)) return true;
if (cast && rules.getStaticType(e).isDynamic) {
@@ -620,8 +623,9 @@ class DownwardsInference {
if (e is ListLiteral) return _inferListLiteral(e, t, errors);
if (e is MapLiteral) return _inferMapLiteral(e, t, errors);
if (e is NamedExpression) return _inferNamedExpression(e, t, errors);
- if (e is InstanceCreationExpression) return _inferInstanceCreationExpression(
- e, t, errors);
+ if (e is InstanceCreationExpression) {
+ return _inferInstanceCreationExpression(e, t, errors);
+ }
errors.add("$e cannot be typed as $t");
return false;
}
@@ -707,6 +711,12 @@ class DownwardsInference {
/// These assume that e is not already a subtype of t
+ bool _inferConditionalExpression(
+ ConditionalExpression e, DartType t, errors) {
+ return _inferExpression(e.thenExpression, t, errors) &&
+ _inferExpression(e.elseExpression, t, errors);
+ }
+
bool _inferInstanceCreationExpression(
InstanceCreationExpression e, DartType t, errors) {
var arguments = e.argumentList.arguments;
« no previous file with comments | « lib/runtime/dart/core.js ('k') | test/checker/checker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698