Add test for reflective use of class that is vertically merged

Bug: 172856713
Change-Id: I566002b39435b9a0cc841e5dd83a26e3ed1c6ed0
diff --git a/src/test/java/com/android/tools/r8/classmerging/vertical/VerticalClassMergerReflectiveNameTest.java b/src/test/java/com/android/tools/r8/classmerging/vertical/VerticalClassMergerReflectiveNameTest.java
new file mode 100644
index 0000000..b196bd2
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/classmerging/vertical/VerticalClassMergerReflectiveNameTest.java
@@ -0,0 +1,107 @@
+// 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.classmerging.vertical;
+
+import static com.android.tools.r8.DiagnosticsMatcher.diagnosticMessage;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThrows;
+
+import com.android.tools.r8.CompilationFailedException;
+import com.android.tools.r8.NeverClassInline;
+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 com.android.tools.r8.ToolHelper.DexVm.Version;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class VerticalClassMergerReflectiveNameTest extends TestBase {
+
+  private final TestParameters parameters;
+
+  @Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters()
+        .withCfRuntimes()
+        .withDexRuntimesStartingFromIncluding(Version.V8_1_0)
+        .withAllApiLevelsAlsoForCf()
+        .build();
+  }
+
+  public VerticalClassMergerReflectiveNameTest(TestParameters parameters) {
+    this.parameters = parameters;
+  }
+
+  @Test
+  public void testRuntime() throws Exception {
+    testForRuntime(parameters)
+        .addProgramClasses(Main.class, A.class, B.class)
+        .run(parameters.getRuntime(), Main.class)
+        .assertSuccessWithOutputLines("A::foo", "B::foo");
+  }
+
+  @Test
+  public void testR8() throws Exception {
+    assertThrows(
+        CompilationFailedException.class,
+        () -> {
+          testForR8(parameters.getBackend())
+              .addProgramClasses(Main.class, A.class, B.class)
+              .addKeepMainRule(Main.class)
+              .setMinApi(parameters.getApiLevel())
+              .enableInliningAnnotations()
+              .enableNeverClassInliningAnnotations()
+              .compileWithExpectedDiagnostics(
+                  diagnostics -> {
+                    diagnostics.assertErrorsMatch(
+                        diagnosticMessage(
+                            containsString(
+                                "Expected vertically merged class `"
+                                    + A.class.getTypeName()
+                                    + "` to be absent")));
+                  });
+        });
+  }
+
+  public static class A {
+
+    @NeverInline
+    public void foo() {
+      System.out.println("A::foo");
+    }
+  }
+
+  @NeverClassInline
+  public static class B extends A {
+
+    @NeverInline
+    public void bar() {
+      System.out.println("B::foo");
+    }
+  }
+
+  public static class Main {
+
+    private static final String className =
+        "com.android.tools.r8.classmerging.vertical.VerticalClassMergerReflectiveNameTest$A";
+
+    static {
+      try {
+        Class.forName(className);
+      } catch (ClassNotFoundException e) {
+      }
+    }
+
+    public static void main(String[] args) {
+      B b = new B();
+      b.foo();
+      b.bar();
+    }
+  }
+}