diff --git a/pkg/compiler/lib/src/ssa/builder_kernel.dart b/pkg/compiler/lib/src/ssa/builder_kernel.dart index 2e03d26e54c..260b3a3afc1 100644 --- a/pkg/compiler/lib/src/ssa/builder_kernel.dart +++ b/pkg/compiler/lib/src/ssa/builder_kernel.dart @@ -719,12 +719,6 @@ class KernelSsaGraphBuilder extends ir.Visitor graph.finalize(); } - /// Pushes a boolean checking [expression] against null. - pushCheckNull(HInstruction expression) { - push(new HIdentity(expression, graph.addConstantNull(closedWorld), null, - commonMasks.boolType)); - } - @override void defaultExpression(ir.Expression expression) { // TODO(het): This is only to get tests working. @@ -2888,9 +2882,6 @@ class KernelSsaGraphBuilder extends ir.Visitor // TODO(het): Decide when to inline @override void visitMethodInvocation(ir.MethodInvocation invocation) { - // Handle `x == null` specially. When these come from null-aware operators, - // there is no mapping in the astAdapter. - if (_handleEqualsNull(invocation)) return; invocation.receiver.accept(this); HInstruction receiver = pop(); Selector selector = _elementMap.getSelector(invocation); @@ -2901,27 +2892,6 @@ class KernelSsaGraphBuilder extends ir.Visitor _visitArgumentsForDynamicTarget(selector, invocation.arguments))); } - bool _handleEqualsNull(ir.MethodInvocation invocation) { - if (invocation.name.name == '==') { - ir.Arguments arguments = invocation.arguments; - if (arguments.types.isEmpty && - arguments.positional.length == 1 && - arguments.named.isEmpty) { - bool finish(ir.Expression comparand) { - comparand.accept(this); - pushCheckNull(pop()); - return true; - } - - ir.Expression receiver = invocation.receiver; - ir.Expression argument = arguments.positional.first; - if (argument is ir.NullLiteral) return finish(receiver); - if (receiver is ir.NullLiteral) return finish(argument); - } - } - return false; - } - HInterceptor _interceptorFor(HInstruction intercepted) { HInterceptor interceptor = new HInterceptor(intercepted, commonMasks.nonNullType); diff --git a/pkg/compiler/lib/src/ssa/kernel_ast_adapter.dart b/pkg/compiler/lib/src/ssa/kernel_ast_adapter.dart index 2a25e1a900f..ae2cd8d1ce8 100644 --- a/pkg/compiler/lib/src/ssa/kernel_ast_adapter.dart +++ b/pkg/compiler/lib/src/ssa/kernel_ast_adapter.dart @@ -580,7 +580,12 @@ class KernelAstTypeInferenceMap implements KernelToTypeInferenceMap { if (send.name.name == '[]=') { return closedWorld.commonMasks.dynamicType; } - return _resultOf(_target).typeOfSend(_astAdapter.getNode(send)); + ast.Node node = _astAdapter.getNodeOrNull(send); + if (node == null) { + assert(send.name.name == '=='); + return closedWorld.commonMasks.dynamicType; + } + return _resultOf(_target).typeOfSend(node); } TypeMask typeOfGet(ir.PropertyGet getter) { diff --git a/tests/compiler/dart2js/kernel/compile_from_dill_test.dart b/tests/compiler/dart2js/kernel/compile_from_dill_test.dart index 22bd53a8605..72d8cd725a3 100644 --- a/tests/compiler/dart2js/kernel/compile_from_dill_test.dart +++ b/tests/compiler/dart2js/kernel/compile_from_dill_test.dart @@ -49,10 +49,17 @@ main() { new Class(''); Class.staticField; var x = null; + var y1 = x == null; + var y2 = null == x; + var z1 = x?.toString(); + var z2 = x ?? y1; + var z3 = x ??= y2; + var w = x == null ? null : x.toString(); for (int i = 0; i < 10; i++) { x = i; if (i == 5) break; } + print(x); return x; } '''