Add test for not maintaining classpath class hierarchy

Bug: b/226054007
Change-Id: I7f7552adc5165dd6b10fce27aa6a3ff540e13f8b
diff --git a/src/test/java/com/android/tools/r8/shaking/ClasspathAndProgramSharedSuperTypeTest.java b/src/test/java/com/android/tools/r8/shaking/ClasspathAndProgramSharedSuperTypeTest.java
new file mode 100644
index 0000000..4363f33
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/shaking/ClasspathAndProgramSharedSuperTypeTest.java
@@ -0,0 +1,81 @@
+// Copyright (c) 2022, 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.shaking;
+
+import static org.hamcrest.core.StringContains.containsString;
+import static org.junit.Assert.assertThrows;
+
+import com.android.tools.r8.CompilationFailedException;
+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.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class ClasspathAndProgramSharedSuperTypeTest extends TestBase {
+
+  @Parameter() public TestParameters parameters;
+
+  @Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimesAndApiLevels().build();
+  }
+
+  @Test
+  public void testR8() throws Exception {
+    // TODO(b/226054007): R8 should maintain classpath type.
+    assertThrows(
+        CompilationFailedException.class,
+        () ->
+            testForR8(parameters.getBackend())
+                .addProgramClasses(SharedSuperType.class, ProgramClass.class, Main.class)
+                .addClasspathClasses(SharedSuperType.class, ClasspathClass.class)
+                .setMinApi(parameters.getApiLevel())
+                .addKeepMainRule(Main.class)
+                .compileWithExpectedDiagnostics(
+                    diagnostics ->
+                        diagnostics.assertErrorMessageThatMatches(
+                            containsString(
+                                "Failed lookup of non-missing type: "
+                                    + typeName(SharedSuperType.class)))));
+  }
+
+  public static class SharedSuperType {
+
+    public void foo() {
+      System.out.println("SharedSuperType::foo");
+    }
+  }
+
+  public static class ClasspathClass extends SharedSuperType {
+
+    @Override
+    public void foo() {
+      System.out.println("ClasspathClass::foo");
+      super.foo();
+    }
+  }
+
+  /* Not referenced in live part of the program */
+  public static class ProgramClass extends SharedSuperType {
+
+    @Override
+    public void foo() {
+      System.out.println("ProgramClass::foo");
+      super.foo();
+    }
+  }
+
+  public static class Main {
+
+    public static void main(String[] args) {
+      new ClasspathClass().foo();
+    }
+  }
+}