Chromium Code Reviews| 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 |