Merge "Reproduction for bug in uninstantiated type optimization"
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/uninstantiatedtypes/NestedInterfaceMethodTest.java b/src/test/java/com/android/tools/r8/ir/optimize/uninstantiatedtypes/NestedInterfaceMethodTest.java
new file mode 100644
index 0000000..7454509
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/ir/optimize/uninstantiatedtypes/NestedInterfaceMethodTest.java
@@ -0,0 +1,103 @@
+// Copyright (c) 2019, 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.uninstantiatedtypes;
+
+import static org.hamcrest.CoreMatchers.containsString;
+
+import com.android.tools.r8.NeverInline;
+import com.android.tools.r8.NeverMerge;
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.utils.AndroidApiLevel;
+import com.android.tools.r8.utils.StringUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/** Reproduction for b/128917897. */
+@RunWith(Parameterized.class)
+public class NestedInterfaceMethodTest extends TestBase {
+
+  private final TestParameters parameters;
+
+  @Parameters(name = "{0}")
+  public static TestParametersCollection params() {
+    return getTestParameters().withAllRuntimes().build();
+  }
+
+  public NestedInterfaceMethodTest(TestParameters parameters) {
+    this.parameters = parameters;
+  }
+
+  @Test
+  public void test() throws Exception {
+    String expectedOutput = StringUtils.lines("In A.m()", "In A.m()");
+
+    if (parameters.getBackend() == Backend.CF) {
+      testForJvm().addTestClasspath().run(TestClass.class).assertSuccessWithOutput(expectedOutput);
+    }
+
+    testForR8(parameters.getBackend())
+        .addInnerClasses(NestedInterfaceMethodTest.class)
+        .addKeepMainRule(TestClass.class)
+        .enableInliningAnnotations()
+        .enableMergeAnnotations()
+        .setMinApi(AndroidApiLevel.B)
+        .run(parameters.getRuntime(), TestClass.class)
+        .assertFailureWithErrorThatMatches(containsString("AbstractMethodError"));
+
+    /*
+    ClassSubject interfaceSubject = inspector.clazz(I.class);
+    assertThat(interfaceSubject, isPresent());
+    assertThat(interfaceSubject.method(Uninstantiated.class.getTypeName(), "m"), isPresent());
+
+    ClassSubject classSubject = inspector.clazz(A.class);
+    assertThat(classSubject, isPresent());
+    assertThat(classSubject.method(Uninstantiated.class.getTypeName(), "m"), isPresent());
+    */
+  }
+
+  static class TestClass {
+
+    public static void main(String[] args) {
+      test(new B());
+      test(new C());
+    }
+
+    @NeverInline
+    private static void test(I obj) {
+      obj.m();
+    }
+  }
+
+  @NeverMerge
+  interface I {
+
+    Uninstantiated m();
+  }
+
+  @NeverMerge
+  interface J extends I {}
+
+  static class A implements J {
+
+    @Override
+    public Uninstantiated m() {
+      System.out.println("In A.m()");
+      return null;
+    }
+  }
+
+  static class B extends A {}
+
+  // The purpose of this class is merely to avoid that the invoke-interface instruction in
+  // TestClass.test() gets devirtualized to an invoke-virtual instruction. Otherwise the method
+  // I.m() would not be present in the output.
+  static class C extends A {}
+
+  static class Uninstantiated {}
+}