Reproduce NPE from missing AppInfoWithLiveness rewriting
Bug: 161735546
Change-Id: I92ef83f646d6681956438917e5331bbbeed39d65
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/B161735546.java b/src/test/java/com/android/tools/r8/ir/optimize/B161735546.java
new file mode 100644
index 0000000..1d880e6
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/ir/optimize/B161735546.java
@@ -0,0 +1,80 @@
+// Copyright (c) 2020, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.android.tools.r8.ir.optimize;
+
+import static org.junit.Assert.assertTrue;
+
+import com.android.tools.r8.CompilationFailedException;
+import com.android.tools.r8.R8TestCompileResult;
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class B161735546 extends TestBase {
+
+ private final TestParameters parameters;
+
+ @Parameterized.Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withAllRuntimesAndApiLevels().build();
+ }
+
+ public B161735546(TestParameters parameters) {
+ this.parameters = parameters;
+ }
+
+ @Test
+ public void test() throws Exception {
+ R8TestCompileResult compileResult = null;
+ try {
+ compileResult =
+ testForR8(parameters.getBackend())
+ .addInnerClasses(B161735546.class)
+ .addKeepMainRule(TestClass.class)
+ .setMinApi(parameters.getApiLevel())
+ .compile();
+ } catch (CompilationFailedException e) {
+ // TODO(b/161735546): Fix NPE.
+ assertTrue(parameters.isDexRuntime());
+ return;
+ }
+
+ compileResult
+ .run(parameters.getRuntime(), TestClass.class)
+ .assertSuccessWithOutputLines("1", "2", "3");
+ }
+
+ static class TestClass {
+ public static void main(String[] args) {
+ new CounterUtils() {}.add(new Counter(), 3);
+ }
+ }
+
+ static class Counter {
+ int i = 0;
+ }
+
+ interface CounterConsumer {
+ void accept(Counter counter);
+ }
+
+ interface CounterUtils {
+ default void add(Counter counter, int i) {
+ if (i == 0) {
+ return;
+ }
+ CounterConsumer continuation =
+ c -> {
+ System.out.println(++counter.i);
+ add(counter, i - 1);
+ };
+ continuation.accept(counter);
+ }
+ }
+}