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

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
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..af2d2dff5fb741f544f8221fb0763cc664071d89 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,14 @@ 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.
+ DartType objectType = compiler.coreTypes.objectType;
Siggi Cherem (dart-lang) 2015/11/26 02:21:48 delete? (seems unused)
sra1 2015/12/01 02:14:10 Done.
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 +1134,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

Powered by Google App Engine
This is Rietveld 408576698