Reproduce class merger bug leading to StackOverflowError

Bug: 133501933
Change-Id: I44a34d4936a1e47e5bb7346c9a5873237036718e
diff --git a/src/test/java/com/android/tools/r8/classmerging/IncorrectRewritingOfInvokeSuperTest.java b/src/test/java/com/android/tools/r8/classmerging/IncorrectRewritingOfInvokeSuperTest.java
new file mode 100644
index 0000000..d4b045d
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/classmerging/IncorrectRewritingOfInvokeSuperTest.java
@@ -0,0 +1,82 @@
+// 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.classmerging;
+
+import static org.hamcrest.core.StringContains.containsString;
+
+import com.android.tools.r8.NeverInline;
+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;
+import org.junit.runners.Parameterized.Parameters;
+
+/** Regression test for b/133501933. */
+@RunWith(Parameterized.class)
+public class IncorrectRewritingOfInvokeSuperTest extends TestBase {
+
+  private final TestParameters parameters;
+
+  @Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimes().build();
+  }
+
+  public IncorrectRewritingOfInvokeSuperTest(TestParameters parameters) {
+    this.parameters = parameters;
+  }
+
+  @Test
+  public void test() throws Exception {
+    testForR8(parameters.getBackend())
+        .addInnerClasses(IncorrectRewritingOfInvokeSuperTest.class)
+        .addKeepMainRule(TestClass.class)
+        .addOptionsModification(options -> options.enableUnusedInterfaceRemoval = false)
+        .enableInliningAnnotations()
+        .noMinification()
+        .setMinApi(parameters.getRuntime())
+        .run(parameters.getRuntime(), TestClass.class)
+        // TODO(b/133501933): Should succeed.
+        .assertFailureWithErrorThatMatches(containsString(StackOverflowError.class.getTypeName()));
+  }
+
+  static class TestClass {
+
+    public static void main(String[] args) {
+      new B() {}.m(new SubArgType());
+    }
+  }
+
+  interface I<U> {
+
+    void m(U arg);
+  }
+
+  abstract static class A implements I<ArgType> {
+
+    @NeverInline
+    @Override
+    public void m(ArgType x) {
+      if (x == null) {
+        throw new RuntimeException();
+      }
+    }
+  }
+
+  static class B extends A {
+
+    @NeverInline
+    @Override
+    public final void m(ArgType x) {
+      super.m(x);
+    }
+  }
+
+  static class ArgType {}
+
+  static class SubArgType extends ArgType {}
+}