Revert "Fail when seeing @CovariantReturnType outside platform builds"
This reverts commit b92ab13a73fe1bc715ca296ad09f2a7943ced4ac.
Change-Id: If69b4fcbd61bc655032f4fa384bb6f349b026e51
diff --git a/src/main/java/com/android/tools/r8/graph/DexAnnotation.java b/src/main/java/com/android/tools/r8/graph/DexAnnotation.java
index 10f0699..cee4f28 100644
--- a/src/main/java/com/android/tools/r8/graph/DexAnnotation.java
+++ b/src/main/java/com/android/tools/r8/graph/DexAnnotation.java
@@ -22,7 +22,6 @@
import com.android.tools.r8.utils.AndroidApiLevel;
import com.android.tools.r8.utils.InternalOptions;
import com.android.tools.r8.utils.Pair;
-import com.android.tools.r8.utils.StringDiagnostic;
import com.android.tools.r8.utils.structural.StructuralItem;
import com.android.tools.r8.utils.structural.StructuralMapping;
import com.android.tools.r8.utils.structural.StructuralSpecification;
@@ -152,12 +151,7 @@
DexString descriptor = annotationType.getDescriptor();
if (descriptor.startsWith(factory.dalvikAnnotationPrefix)) {
if (descriptor.startsWith(factory.dalvikAnnotationCodegenCovariantReturnTypePrefix)) {
- if (options.processCovariantReturnTypeAnnotations) {
- return true;
- }
- throw options.reporter.fatalError(
- new StringDiagnostic(
- "Unexpected @CovariantReturnType annotation in non-platform build"));
+ return options.processCovariantReturnTypeAnnotations;
}
return descriptor.startsWith(factory.dalvikAnnotationOptimizationPrefix);
}
diff --git a/src/test/java/com/android/tools/r8/ir/desugar/annotations/CovariantReturnTypeAnnotationTransformerTest.java b/src/test/java/com/android/tools/r8/ir/desugar/annotations/CovariantReturnTypeAnnotationTransformerTest.java
index d37c3f8..7853976 100644
--- a/src/test/java/com/android/tools/r8/ir/desugar/annotations/CovariantReturnTypeAnnotationTransformerTest.java
+++ b/src/test/java/com/android/tools/r8/ir/desugar/annotations/CovariantReturnTypeAnnotationTransformerTest.java
@@ -4,21 +4,14 @@
package com.android.tools.r8.ir.desugar.annotations;
-import static com.android.tools.r8.DiagnosticsMatcher.diagnosticMessage;
-import static com.android.tools.r8.DiagnosticsMatcher.diagnosticType;
-import static com.android.tools.r8.utils.codeinspector.AssertUtils.assertFailsCompilation;
import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
-import static junit.framework.TestCase.assertTrue;
-import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.AllOf.allOf;
import static org.junit.Assert.assertEquals;
import com.android.tools.r8.AsmTestBase;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.TestParametersCollection;
import com.android.tools.r8.ToolHelper;
-import com.android.tools.r8.utils.StringDiagnostic;
import com.android.tools.r8.utils.codeinspector.ClassSubject;
import com.android.tools.r8.utils.codeinspector.CodeInspector;
import com.android.tools.r8.utils.codeinspector.MethodSubject;
@@ -26,6 +19,7 @@
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
+import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -40,6 +34,7 @@
public static final String CRTS_INNER_NAME = "CovariantReturnTypes";
public static final String CRTS_BINARY_NAME = CRT_BINARY_NAME + "$" + CRTS_INNER_NAME;
+ public static final String CRT_TYPE_NAME = CRT_BINARY_NAME.replace('/', '.');
public static final String CRTS_TYPE_NAME = CRT_BINARY_NAME.replace('/', '.');
@Parameter(0)
@@ -105,8 +100,7 @@
checkPresenceOfCovariantAnnotations(input, true);
// Version 2 of the library should always work.
- succeedsWithOption(input, true, true);
- failsCompilationByDefault(input);
+ succeedsIndependentOfFlag(input, true);
}
@Test
@@ -130,7 +124,7 @@
// If CovariantReturnType annotations are ignored, then there will be no methods with the
// signatures "L.../B;->method()L.../B;" and "L.../C;->method()L.../C;".
- failsCompilationByDefault(input);
+ failsWithOption(input, false);
}
@Test
@@ -224,24 +218,7 @@
.assertSuccessWithOutput(getExpectedOutput());
}
- private void failsCompilationByDefault(List<byte[]> input) throws Exception {
- assertFailsCompilation(
- () ->
- testForD8(parameters.getBackend())
- .addProgramClassFileData(input)
- .setMinApi(parameters)
- .compileWithExpectedDiagnostics(
- diagnostics ->
- diagnostics.assertErrorThatMatches(
- allOf(
- diagnosticType(StringDiagnostic.class),
- diagnosticMessage(
- equalTo(
- "Unexpected @CovariantReturnType annotation in non-platform"
- + " build"))))));
- }
-
- private void failsRuntimeWithOption(List<byte[]> input, boolean option) throws Exception {
+ private void failsWithOption(List<byte[]> input, boolean option) throws Exception {
testForD8(parameters.getBackend())
.addProgramClassFileData(input)
.addOptionsModification(options -> options.processCovariantReturnTypeAnnotations = option)
@@ -259,8 +236,8 @@
}
private void failsIndependentOfFlag(List<byte[]> input) throws Exception {
- failsRuntimeWithOption(input, true);
- failsRuntimeWithOption(input, false);
+ failsWithOption(input, true);
+ failsWithOption(input, false);
}
private void checkPresenceOfCovariantAnnotations(List<byte[]> input, boolean expected)
@@ -294,34 +271,34 @@
MethodSubject methodA =
clazzA.method(A.class.getCanonicalName(), "method", Collections.emptyList());
assertThat(methodA, isPresent());
- assertTrue(!methodA.getMethod().isSyntheticMethod());
+ Assert.assertTrue(!methodA.getMethod().isSyntheticMethod());
MethodSubject methodB =
clazzB.method(A.class.getCanonicalName(), "method", Collections.emptyList());
assertThat(methodB, isPresent());
- assertTrue(!methodB.getMethod().isSyntheticMethod());
+ Assert.assertTrue(!methodB.getMethod().isSyntheticMethod());
MethodSubject methodC =
clazzC.method(A.class.getCanonicalName(), "method", Collections.emptyList());
assertThat(methodC, isPresent());
- assertTrue(!methodC.getMethod().isSyntheticMethod());
+ Assert.assertTrue(!methodC.getMethod().isSyntheticMethod());
// Check that a synthetic method has been added to class B.
MethodSubject methodB2 =
clazzB.method(B.class.getCanonicalName(), "method", Collections.emptyList());
assertThat(methodB2, isPresent());
- assertTrue(methodB2.getMethod().isSyntheticMethod());
+ Assert.assertTrue(methodB2.getMethod().isSyntheticMethod());
// Check that two synthetic methods have been added to class C.
MethodSubject methodC2 =
clazzC.method(B.class.getCanonicalName(), "method", Collections.emptyList());
assertThat(methodC2, isPresent());
- assertTrue(methodC2.getMethod().isSyntheticMethod());
+ Assert.assertTrue(methodC2.getMethod().isSyntheticMethod());
MethodSubject methodC3 =
clazzC.method(C.class.getCanonicalName(), "method", Collections.emptyList());
assertThat(methodC3, isPresent());
- assertTrue(methodC3.getMethod().isSyntheticMethod());
+ Assert.assertTrue(methodC3.getMethod().isSyntheticMethod());
// Get classes D, E, and F.
ClassSubject clazzD = inspector.clazz(D.class.getCanonicalName());
@@ -337,34 +314,34 @@
MethodSubject methodD =
clazzD.method(D.class.getCanonicalName(), "method", Collections.emptyList());
assertThat(methodD, isPresent());
- assertTrue(!methodD.getMethod().isSyntheticMethod());
+ Assert.assertTrue(!methodD.getMethod().isSyntheticMethod());
MethodSubject methodE =
clazzE.method(D.class.getCanonicalName(), "method", Collections.emptyList());
assertThat(methodE, isPresent());
- assertTrue(!methodE.getMethod().isSyntheticMethod());
+ Assert.assertTrue(!methodE.getMethod().isSyntheticMethod());
MethodSubject methodF =
clazzF.method(D.class.getCanonicalName(), "method", Collections.emptyList());
assertThat(methodF, isPresent());
- assertTrue(!methodF.getMethod().isSyntheticMethod());
+ Assert.assertTrue(!methodF.getMethod().isSyntheticMethod());
// Check that a synthetic method has been added to class E.
MethodSubject methodE2 =
clazzE.method(E.class.getCanonicalName(), "method", Collections.emptyList());
assertThat(methodE2, isPresent());
- assertTrue(methodE2.getMethod().isSyntheticMethod());
+ Assert.assertTrue(methodE2.getMethod().isSyntheticMethod());
// Check that two synthetic methods have been added to class F.
MethodSubject methodF2 =
clazzF.method(E.class.getCanonicalName(), "method", Collections.emptyList());
assertThat(methodF2, isPresent());
- assertTrue(methodF2.getMethod().isSyntheticMethod());
+ Assert.assertTrue(methodF2.getMethod().isSyntheticMethod());
MethodSubject methodF3 =
clazzF.method(F.class.getCanonicalName(), "method", Collections.emptyList());
assertThat(methodF3, isPresent());
- assertTrue(methodF3.getMethod().isSyntheticMethod());
+ Assert.assertTrue(methodF3.getMethod().isSyntheticMethod());
}
private String getExpectedOutput() {