Pin super types and members for library classes extending program
This will ensure that program works correctly if there are usages of
the library classes.
Bug: 150844383
Change-Id: Iffca7b9e3ecd5f5387cbab2bf0c2f75cb222e7c4
diff --git a/src/main/java/com/android/tools/r8/shaking/Enqueuer.java b/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
index dc426ea..422ec43 100644
--- a/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
+++ b/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
@@ -1584,14 +1584,30 @@
// main dex lists we allow this.
return;
}
-
- if (dontWarnPatterns.matches(context.type)) {
- // Ignore.
- return;
- }
-
DexClass holder = appView.definitionFor(type);
if (holder != null && !holder.isLibraryClass()) {
+ if (forceProguardCompatibility) {
+ // To ensure that the program works correctly we have to pin all super types and members
+ // in the tree.
+ appInfo.forEachSuperType(
+ holder,
+ (dexType, ignored) -> {
+ if (holder.isProgramClass()) {
+ DexReference holderReference = holder.toReference();
+ pinnedItems.add(holderReference);
+ rootSet.shouldNotBeMinified(holderReference);
+ for (DexEncodedMember<?, ?> member : holder.members()) {
+ DexMember<?, ?> memberReference = member.toReference();
+ pinnedItems.add(memberReference);
+ rootSet.shouldNotBeMinified(memberReference);
+ }
+ }
+ });
+ }
+ if (dontWarnPatterns.matches(context.type)) {
+ // Ignore.
+ return;
+ }
Diagnostic message =
new StringDiagnostic(
"Library class "
diff --git a/src/test/java/com/android/tools/r8/naming/LibraryClassInheritingFromProgramClassNamingTest.java b/src/test/java/com/android/tools/r8/naming/LibraryClassInheritingFromProgramClassNamingTest.java
index 6b3550e..a6c49e4 100644
--- a/src/test/java/com/android/tools/r8/naming/LibraryClassInheritingFromProgramClassNamingTest.java
+++ b/src/test/java/com/android/tools/r8/naming/LibraryClassInheritingFromProgramClassNamingTest.java
@@ -63,8 +63,7 @@
+ TestCase.class.getTypeName()))
.addRunClasspathFiles(libraryResult.writeToZip())
.run(parameters.getRuntime(), Main.class)
- // TODO(b/150844383): Pin supertypes from re-entry point into library.
- .assertFailureWithErrorThatThrows(VerifyError.class);
+ .assertSuccessWithOutputLines("TestCase.foo");
}
public interface I {