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

Unified Diff: pkg/compiler/lib/src/inferrer/inferrer_visitor.dart

Issue 1469353008: dart2js: Type inferrence: Account for implicit null test in '??' and '??='. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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/compiler/lib/src/inferrer/simple_types_inferrer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/inferrer/inferrer_visitor.dart
diff --git a/pkg/compiler/lib/src/inferrer/inferrer_visitor.dart b/pkg/compiler/lib/src/inferrer/inferrer_visitor.dart
index f9dc9ebcc5ad769dbb181c348179eec3ff4e2298..fbb788045dd280d44262f851e92dc5eb3d49fca8 100644
--- a/pkg/compiler/lib/src/inferrer/inferrer_visitor.dart
+++ b/pkg/compiler/lib/src/inferrer/inferrer_visitor.dart
@@ -91,6 +91,11 @@ abstract class TypeSystem<T> {
T narrowType(T type, DartType annotation, {bool isNullable: true});
/**
+ * Returns the non-nullable type [T].
+ */
+ T narrowNotNull(T type);
+
+ /**
* Returns a new type that unions [firstInput] and [secondInput].
*/
T allocateDiamondPhi(T firstInput, T secondInput);
@@ -469,9 +474,13 @@ class LocalsHandler<T> {
SendSet send = node != null ? node.asSendSet() : null;
if (send != null && send.isIfNullAssignment && currentType != null) {
- // If-null assignments may return either the new or the original value.
+ // If-null assignments may return either the new or the original value
+ // narrowed to non-null.
type = types.addPhiInput(
- local, types.allocatePhi(locals.block, local, currentType), type);
+ local,
+ types.allocatePhi(locals.block, local,
+ types.narrowNotNull(currentType)),
+ type);
}
locals[local] = type;
if (currentType != type) {
@@ -1124,7 +1133,7 @@ abstract class InferrerVisitor<T, E extends MinimalInferrerEngine<T>>
T visitIfNull(Send node, Node left, Node right, _) {
T firstType = visit(left);
T secondType = visit(right);
- return types.allocateDiamondPhi(firstType, secondType);
+ return types.allocateDiamondPhi(types.narrowNotNull(firstType), secondType);
}
@override
« no previous file with comments | « no previous file | pkg/compiler/lib/src/inferrer/simple_types_inferrer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698