Only use Object for pruned types in type-arguments

Bug: 187134647
Bug: 185098797
Change-Id: I2714a8ed5354cf9329d26b196e47bbbf6f96e9de
diff --git a/src/main/java/com/android/tools/r8/graph/GenericSignaturePartialTypeArgumentApplier.java b/src/main/java/com/android/tools/r8/graph/GenericSignaturePartialTypeArgumentApplier.java
index adb256f..c381074 100644
--- a/src/main/java/com/android/tools/r8/graph/GenericSignaturePartialTypeArgumentApplier.java
+++ b/src/main/java/com/android/tools/r8/graph/GenericSignaturePartialTypeArgumentApplier.java
@@ -12,7 +12,6 @@
 import com.android.tools.r8.graph.GenericSignature.FormalTypeParameter;
 import com.android.tools.r8.graph.GenericSignature.MethodTypeSignature;
 import com.android.tools.r8.graph.GenericSignature.ReturnType;
-import com.android.tools.r8.graph.GenericSignature.StarFieldTypeSignature;
 import com.android.tools.r8.graph.GenericSignature.TypeSignature;
 import com.android.tools.r8.graph.GenericSignature.WildcardIndicator;
 import com.android.tools.r8.utils.ListUtils;
@@ -133,9 +132,7 @@
     if (typeArguments.isEmpty() || !hasGenericTypeParameters.test(type)) {
       return getEmptyTypeArguments();
     }
-    // Wildcards can only be called be used in certain positions:
-    // https://docs.oracle.com/javase/tutorial/java/generics/wildcards.html
-    return ListUtils.mapOrElse(typeArguments, arg -> visitFieldTypeSignature(arg, true));
+    return ListUtils.mapOrElse(typeArguments, this::visitFieldTypeSignature);
   }
 
   @Override
@@ -208,11 +205,6 @@
 
   @Override
   public FieldTypeSignature visitFieldTypeSignature(FieldTypeSignature fieldSignature) {
-    return visitFieldTypeSignature(fieldSignature, false);
-  }
-
-  private FieldTypeSignature visitFieldTypeSignature(
-      FieldTypeSignature fieldSignature, boolean canUseWildcardInArguments) {
     if (fieldSignature.isStar()) {
       return fieldSignature;
     } else if (fieldSignature.isClassTypeSignature()) {
@@ -228,9 +220,7 @@
         if (substitution == null) {
           substitution = objectType;
         }
-        return substitution == objectType && canUseWildcardInArguments
-            ? StarFieldTypeSignature.getStarFieldTypeSignature()
-            : new ClassTypeSignature(substitution).asArgument(WildcardIndicator.NONE);
+        return new ClassTypeSignature(substitution).asArgument(WildcardIndicator.NONE);
       }
       return fieldSignature;
     }
diff --git a/src/main/java/com/android/tools/r8/graph/GenericSignatureTypeRewriter.java b/src/main/java/com/android/tools/r8/graph/GenericSignatureTypeRewriter.java
index 956b076..93b3b47 100644
--- a/src/main/java/com/android/tools/r8/graph/GenericSignatureTypeRewriter.java
+++ b/src/main/java/com/android/tools/r8/graph/GenericSignatureTypeRewriter.java
@@ -13,8 +13,8 @@
 import com.android.tools.r8.graph.GenericSignature.FormalTypeParameter;
 import com.android.tools.r8.graph.GenericSignature.MethodTypeSignature;
 import com.android.tools.r8.graph.GenericSignature.ReturnType;
-import com.android.tools.r8.graph.GenericSignature.StarFieldTypeSignature;
 import com.android.tools.r8.graph.GenericSignature.TypeSignature;
+import com.android.tools.r8.graph.GenericSignature.WildcardIndicator;
 import com.android.tools.r8.utils.ListUtils;
 import java.util.List;
 import java.util.function.Function;
@@ -230,7 +230,7 @@
           fieldTypeSignature -> {
             FieldTypeSignature rewrittenSignature = visitFieldTypeSignature(fieldTypeSignature);
             return rewrittenSignature == null
-                ? StarFieldTypeSignature.getStarFieldTypeSignature()
+                ? objectTypeSignature.asArgument(WildcardIndicator.NONE)
                 : rewrittenSignature;
           });
     }
diff --git a/src/test/java/com/android/tools/r8/graph/genericsignature/GenericSignaturePartialTypeArgumentApplierTest.java b/src/test/java/com/android/tools/r8/graph/genericsignature/GenericSignaturePartialTypeArgumentApplierTest.java
index c1d8c5f..64f2ac3 100644
--- a/src/test/java/com/android/tools/r8/graph/genericsignature/GenericSignaturePartialTypeArgumentApplierTest.java
+++ b/src/test/java/com/android/tools/r8/graph/genericsignature/GenericSignaturePartialTypeArgumentApplierTest.java
@@ -67,7 +67,7 @@
             BiPredicateUtils.alwaysFalse(),
             alwaysTrue(),
             "(LList<TT;>;)LList<TR;>;",
-            "(LList<*>;)LList<*>;")
+            "(LList<Ljava/lang/Object;>;)LList<Ljava/lang/Object;>;")
         .assertNoMessages();
   }
 
diff --git a/src/test/java/com/android/tools/r8/graph/genericsignature/GenericSignaturePrunedOuterTest.java b/src/test/java/com/android/tools/r8/graph/genericsignature/GenericSignaturePrunedOuterTest.java
index ebca08d..af2bb7f 100644
--- a/src/test/java/com/android/tools/r8/graph/genericsignature/GenericSignaturePrunedOuterTest.java
+++ b/src/test/java/com/android/tools/r8/graph/genericsignature/GenericSignaturePrunedOuterTest.java
@@ -55,18 +55,15 @@
   public void checkSignatures(CodeInspector inspector) {
     checkSignature(
         inspector.clazz(Bar.class.getTypeName() + "$1"),
-        "L" + binaryName(Foo.class) + "<*" + descriptor(Main.class) + ">;");
+        "L" + binaryName(Foo.class) + "<Ljava/lang/Object;" + descriptor(Main.class) + ">;");
     checkSignature(
-        inspector.clazz(Bar.class.getTypeName() + "$2"), "L" + binaryName(Foo.class) + "<**>;");
+        inspector.clazz(Bar.class.getTypeName() + "$2"),
+        "L" + binaryName(Foo.class) + "<Ljava/lang/Object;Ljava/lang/Object;>;");
   }
 
   private void checkSignature(ClassSubject classSubject, String expectedSignature) {
     assertThat(classSubject, isPresent());
-    // TODO(b/185098797): Make sure to work for full mode.
-    if (!isCompat) {
-      return;
-    }
-    assertEquals(expectedSignature, classSubject.getFinalSignatureAttribute());
+    assertEquals(isCompat ? expectedSignature : null, classSubject.getFinalSignatureAttribute());
   }
 
   public abstract static class Foo<T, R> {
diff --git a/src/test/java/com/android/tools/r8/naming/b126592786/B126592786.java b/src/test/java/com/android/tools/r8/naming/b126592786/B126592786.java
index b2614a3..fb9c53e 100644
--- a/src/test/java/com/android/tools/r8/naming/b126592786/B126592786.java
+++ b/src/test/java/com/android/tools/r8/naming/b126592786/B126592786.java
@@ -57,7 +57,7 @@
         .compile()
         .inspect(
             inspector -> {
-              String genericTypeDescriptor = "*";
+              String genericTypeDescriptor = "Ljava/lang/Object;";
               if (genericTypeLive) {
                 ClassSubject genericType = inspector.clazz(GenericType.class);
                 assertThat(genericType, isPresentAndRenamed(minify));