Additional diagnostics for @JvmDefaultWithCompatibility
This commit is contained in:
+28
@@ -33922,6 +33922,34 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class JvmDefaultWithCompatibility {
|
||||
@Test
|
||||
public void testAllFilesPresentInJvmDefaultWithCompatibility() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("target6.kt")
|
||||
public void testTarget6() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility/target6.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("target8.kt")
|
||||
public void testTarget8() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility/target8.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("target8Disabled.kt")
|
||||
public void testTarget8Disabled() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility/target8Disabled.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithoutCompatibility")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+28
@@ -33922,6 +33922,34 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class JvmDefaultWithCompatibility {
|
||||
@Test
|
||||
public void testAllFilesPresentInJvmDefaultWithCompatibility() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("target6.kt")
|
||||
public void testTarget6() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility/target6.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("target8.kt")
|
||||
public void testTarget8() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility/target8.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("target8Disabled.kt")
|
||||
public void testTarget8Disabled() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility/target8Disabled.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithoutCompatibility")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+28
@@ -33922,6 +33922,34 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class JvmDefaultWithCompatibility {
|
||||
@Test
|
||||
public void testAllFilesPresentInJvmDefaultWithCompatibility() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("target6.kt")
|
||||
public void testTarget6() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility/target6.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("target8.kt")
|
||||
public void testTarget8() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility/target8.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("target8Disabled.kt")
|
||||
public void testTarget8Disabled() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility/target8Disabled.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithoutCompatibility")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+35
-10
@@ -51,16 +51,7 @@ class JvmDefaultChecker(private val jvmTarget: JvmTarget, project: Project) : De
|
||||
}
|
||||
}
|
||||
|
||||
descriptor.annotations.findAnnotation(JVM_DEFAULT_NO_COMPATIBILITY_FQ_NAME)?.let { annotationDescriptor ->
|
||||
val reportOn = DescriptorToSourceUtils.getSourceFromAnnotation(annotationDescriptor) ?: declaration
|
||||
if (jvmTarget == JvmTarget.JVM_1_6) {
|
||||
context.trace.report(ErrorsJvm.JVM_DEFAULT_IN_JVM6_TARGET.on(reportOn, "JvmDefaultWithoutCompatibility"))
|
||||
return@check
|
||||
} else if (!jvmDefaultMode.isEnabled) {
|
||||
context.trace.report(ErrorsJvm.JVM_DEFAULT_IN_DECLARATION.on(reportOn, "JvmDefaultWithoutCompatibility"))
|
||||
return@check
|
||||
}
|
||||
}
|
||||
if (checkJvmCompatibilityAnnotations(descriptor, declaration, context, jvmDefaultMode)) return
|
||||
|
||||
if (jvmDefaultAnnotation == null && !jvmDefaultMode.forAllMethodsWithBody && isInterface(descriptor.containingDeclaration)) {
|
||||
val memberDescriptor = descriptor as? CallableMemberDescriptor ?: return
|
||||
@@ -142,6 +133,40 @@ class JvmDefaultChecker(private val jvmTarget: JvmTarget, project: Project) : De
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkJvmCompatibilityAnnotations(
|
||||
descriptor: DeclarationDescriptor,
|
||||
declaration: KtDeclaration,
|
||||
context: DeclarationCheckerContext,
|
||||
jvmDefaultMode: JvmDefaultMode
|
||||
): Boolean {
|
||||
descriptor.annotations.findAnnotation(JVM_DEFAULT_NO_COMPATIBILITY_FQ_NAME)?.let { annotationDescriptor ->
|
||||
val reportOn = DescriptorToSourceUtils.getSourceFromAnnotation(annotationDescriptor) ?: declaration
|
||||
if (jvmTarget == JvmTarget.JVM_1_6) {
|
||||
context.trace.report(ErrorsJvm.JVM_DEFAULT_IN_JVM6_TARGET.on(reportOn, "JvmDefaultWithoutCompatibility"))
|
||||
return true
|
||||
} else if (!jvmDefaultMode.isEnabled) {
|
||||
context.trace.report(ErrorsJvm.JVM_DEFAULT_IN_DECLARATION.on(reportOn, "JvmDefaultWithoutCompatibility"))
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
descriptor.annotations.findAnnotation(JVM_DEFAULT_WITH_COMPATIBILITY_FQ_NAME)?.let { annotationDescriptor ->
|
||||
val reportOn = DescriptorToSourceUtils.getSourceFromAnnotation(annotationDescriptor) ?: declaration
|
||||
if (jvmTarget == JvmTarget.JVM_1_6) {
|
||||
context.trace.report(ErrorsJvm.JVM_DEFAULT_IN_JVM6_TARGET.on(reportOn, "JvmDefaultWithCompatibility"))
|
||||
return true
|
||||
} else if (jvmDefaultMode != JvmDefaultMode.ALL_INCOMPATIBLE) {
|
||||
context.trace.report(ErrorsJvm.JVM_DEFAULT_WITH_COMPATIBILITY_IN_DECLARATION.on(reportOn))
|
||||
return true
|
||||
} else if (!isInterface(descriptor)) {
|
||||
context.trace.report(ErrorsJvm.JVM_DEFAULT_WITH_COMPATIBILITY_NOT_ON_INTERFACE.on(reportOn))
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private fun checkSpecializationInCompatibilityMode(
|
||||
inheritedFun: FunctionDescriptor,
|
||||
actualImplementation: FunctionDescriptor,
|
||||
|
||||
+2
@@ -166,6 +166,8 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
||||
MAP.put(JVM_DEFAULT_IN_JVM6_TARGET,"''@{0}'' is only supported since JVM target 1.8. Recompile with ''-jvm-target 1.8''", STRING);
|
||||
MAP.put(JVM_DEFAULT_REQUIRED_FOR_OVERRIDE, "'@JvmDefault' is required for an override of a '@JvmDefault' member");
|
||||
MAP.put(JVM_DEFAULT_IN_DECLARATION, "Usage of ''@{0}'' is only allowed with -Xjvm-default option", STRING);
|
||||
MAP.put(JVM_DEFAULT_WITH_COMPATIBILITY_IN_DECLARATION, "Usage of '@JvmDefaultWithCompatibility' is only allowed with '-Xjvm-default=all' option");
|
||||
MAP.put(JVM_DEFAULT_WITH_COMPATIBILITY_NOT_ON_INTERFACE, "'@JvmDefaultWithCompatibility' annotation is only allowed on interfaces");
|
||||
MAP.put(USAGE_OF_JVM_DEFAULT_THROUGH_SUPER_CALL, "Super calls of '@JvmDefault' members are only allowed with -Xjvm-default option");
|
||||
MAP.put(NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT, "Non-@JvmDefault interface method cannot override default Java method. Please annotate this method with @JvmDefault or enable `-Xjvm-default=all|all-compatibility`");
|
||||
MAP.put(EXPLICIT_METADATA_IS_DISALLOWED, "Explicit @Metadata is disallowed");
|
||||
|
||||
@@ -124,6 +124,8 @@ public interface ErrorsJvm {
|
||||
DiagnosticFactory1<PsiElement, String> JVM_DEFAULT_IN_JVM6_TARGET = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<KtDeclaration> JVM_DEFAULT_REQUIRED_FOR_OVERRIDE = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory1<KtElement, String> JVM_DEFAULT_IN_DECLARATION = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
DiagnosticFactory0<KtElement> JVM_DEFAULT_WITH_COMPATIBILITY_IN_DECLARATION = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtElement> JVM_DEFAULT_WITH_COMPATIBILITY_NOT_ON_INTERFACE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> USAGE_OF_JVM_DEFAULT_THROUGH_SUPER_CALL = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<PsiElement> LOCAL_JVM_RECORD = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// !JVM_TARGET: 1.6
|
||||
|
||||
@JvmDefaultWithCompatibility
|
||||
interface A {}
|
||||
|
||||
@JvmDefaultWithCompatibility
|
||||
class B : A {}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// !JVM_TARGET: 1.6
|
||||
|
||||
<!JVM_DEFAULT_IN_JVM6_TARGET!>@JvmDefaultWithCompatibility<!>
|
||||
interface A {}
|
||||
|
||||
<!JVM_DEFAULT_IN_JVM6_TARGET!>@JvmDefaultWithCompatibility<!>
|
||||
class B : A {}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package
|
||||
|
||||
@kotlin.jvm.JvmDefaultWithCompatibility public interface A {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmDefaultWithCompatibility public final class B : A {
|
||||
public constructor B()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// !JVM_TARGET: 1.8
|
||||
// !JVM_DEFAULT_MODE: all
|
||||
|
||||
@JvmDefaultWithCompatibility
|
||||
interface A<T> {
|
||||
fun test(p: T) {}
|
||||
}
|
||||
|
||||
@JvmDefaultWithCompatibility
|
||||
class B : A<String> {}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// !JVM_TARGET: 1.8
|
||||
// !JVM_DEFAULT_MODE: all
|
||||
|
||||
@JvmDefaultWithCompatibility
|
||||
interface A<T> {
|
||||
fun test(p: T) {}
|
||||
}
|
||||
|
||||
<!JVM_DEFAULT_WITH_COMPATIBILITY_NOT_ON_INTERFACE!>@JvmDefaultWithCompatibility<!>
|
||||
class B : A<String> {}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package
|
||||
|
||||
@kotlin.jvm.JvmDefaultWithCompatibility public interface A</*0*/ T> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open fun test(/*0*/ p: T): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmDefaultWithCompatibility public final class B : A<kotlin.String> {
|
||||
public constructor B()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun test(/*0*/ p: kotlin.String): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// !JVM_TARGET: 1.8
|
||||
|
||||
@JvmDefaultWithCompatibility
|
||||
interface A<T> {
|
||||
fun test(p: T) {}
|
||||
}
|
||||
|
||||
@JvmDefaultWithCompatibility
|
||||
class B : A<String> {}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// !JVM_TARGET: 1.8
|
||||
|
||||
<!JVM_DEFAULT_WITH_COMPATIBILITY_IN_DECLARATION!>@JvmDefaultWithCompatibility<!>
|
||||
interface A<T> {
|
||||
fun test(p: T) {}
|
||||
}
|
||||
|
||||
<!JVM_DEFAULT_WITH_COMPATIBILITY_IN_DECLARATION!>@JvmDefaultWithCompatibility<!>
|
||||
class B : A<String> {}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package
|
||||
|
||||
@kotlin.jvm.JvmDefaultWithCompatibility public interface A</*0*/ T> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open fun test(/*0*/ p: T): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmDefaultWithCompatibility public final class B : A<kotlin.String> {
|
||||
public constructor B()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun test(/*0*/ p: kotlin.String): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Generated
+28
@@ -34018,6 +34018,34 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class JvmDefaultWithCompatibility {
|
||||
@Test
|
||||
public void testAllFilesPresentInJvmDefaultWithCompatibility() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("target6.kt")
|
||||
public void testTarget6() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility/target6.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("target8.kt")
|
||||
public void testTarget8() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility/target8.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("target8Disabled.kt")
|
||||
public void testTarget8Disabled() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithCompatibility/target8Disabled.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultWithoutCompatibility")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
Reference in New Issue
Block a user