[FIR] Do not enhance nullability for annotation interface field types.

Java annotation interface fields are constant declarations that can
have any Java type and are not restricted in the same way that
method return types are for annotation interfaces.

#KT-65482 Fixed
This commit is contained in:
Mads Ager
2024-02-02 12:11:03 +01:00
committed by Space Team
parent f5d0a5b92d
commit 79eee6de4f
12 changed files with 99 additions and 3 deletions
@@ -31262,6 +31262,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
runTest("compiler/testData/codegen/box/javaInterop/kt48590.kt");
}
@Test
@TestMetadata("kt65482.kt")
public void testKt65482() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/kt65482.kt");
}
@Test
@TestMetadata("lambdaInstanceOf.kt")
public void testLambdaInstanceOf() throws Exception {
@@ -31262,6 +31262,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
runTest("compiler/testData/codegen/box/javaInterop/kt48590.kt");
}
@Test
@TestMetadata("kt65482.kt")
public void testKt65482() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/kt65482.kt");
}
@Test
@TestMetadata("lambdaInstanceOf.kt")
public void testLambdaInstanceOf() throws Exception {
@@ -30931,6 +30931,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/javaInterop/kt48590.kt");
}
@Test
@TestMetadata("kt65482.kt")
public void testKt65482() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/kt65482.kt");
}
@Test
@TestMetadata("lambdaInstanceOf.kt")
public void testLambdaInstanceOf() throws Exception {
@@ -30931,6 +30931,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
runTest("compiler/testData/codegen/box/javaInterop/kt48590.kt");
}
@Test
@TestMetadata("kt65482.kt")
public void testKt65482() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/kt65482.kt");
}
@Test
@TestMetadata("lambdaInstanceOf.kt")
public void testLambdaInstanceOf() throws Exception {
@@ -30931,6 +30931,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/javaInterop/kt48590.kt");
}
@Test
@TestMetadata("kt65482.kt")
public void testKt65482() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/kt65482.kt");
}
@Test
@TestMetadata("lambdaInstanceOf.kt")
public void testLambdaInstanceOf() throws Exception {
@@ -632,10 +632,19 @@ class FirSignatureEnhancement(
defaultQualifiers: JavaTypeQualifiersByElementType?,
predefinedEnhancementInfo: PredefinedFunctionEnhancementInfo?
): FirResolvedTypeRef {
val containerApplicabilityType = if (owner is FirJavaField)
val containerApplicabilityType = if (owner is FirJavaField) {
AnnotationQualifierApplicabilityType.FIELD
else
} else {
AnnotationQualifierApplicabilityType.METHOD_RETURN_TYPE
}
val forAnnotationMember = if (owner is FirJavaField) {
// Fields in annotation interfaces are constant declarations that can have any Java type.
// For example: public @interface MyApi { Integer field = -1; }
// Therefore, for such annotation interface fields, we use default Java type enhancement.
false
} else {
this.owner.classKind == ClassKind.ANNOTATION_CLASS
}
return owner.enhance(
overriddenMembers,
owner,
@@ -644,7 +653,7 @@ class FirSignatureEnhancement(
containerApplicabilityType,
TypeInSignature.Return,
predefinedEnhancementInfo?.returnTypeInfo,
forAnnotationMember = this.owner.classKind == ClassKind.ANNOTATION_CLASS
forAnnotationMember = forAnnotationMember
)
}
+28
View File
@@ -0,0 +1,28 @@
// WITH_STDLIB
// TARGET_BACKEND: JVM
// FILE: MyApi.java
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.CLASS)
@Target({
ElementType.FIELD,
ElementType.METHOD,
ElementType.TYPE,
ElementType.CONSTRUCTOR,
ElementType.PACKAGE
})
public @interface MyApi {
Integer LATEST = -1;
long value();
}
// FILE: main.kt
fun box(): String {
if (-1 == MyApi.LATEST) return "OK"
return "NOT OK"
}
@@ -30931,6 +30931,12 @@ public class JvmAbiConsistencyTestBoxGenerated extends AbstractJvmAbiConsistency
runTest("compiler/testData/codegen/box/javaInterop/kt48590.kt");
}
@Test
@TestMetadata("kt65482.kt")
public void testKt65482() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/kt65482.kt");
}
@Test
@TestMetadata("lambdaInstanceOf.kt")
public void testLambdaInstanceOf() throws Exception {
@@ -29119,6 +29119,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/javaInterop/kt48590.kt");
}
@Test
@TestMetadata("kt65482.kt")
public void testKt65482() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/kt65482.kt");
}
@Test
@TestMetadata("lambdaInstanceOf.kt")
public void testLambdaInstanceOf() throws Exception {
@@ -30931,6 +30931,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/javaInterop/kt48590.kt");
}
@Test
@TestMetadata("kt65482.kt")
public void testKt65482() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/kt65482.kt");
}
@Test
@TestMetadata("lambdaInstanceOf.kt")
public void testLambdaInstanceOf() throws Exception {
@@ -30931,6 +30931,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
runTest("compiler/testData/codegen/box/javaInterop/kt48590.kt");
}
@Test
@TestMetadata("kt65482.kt")
public void testKt65482() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/kt65482.kt");
}
@Test
@TestMetadata("lambdaInstanceOf.kt")
public void testLambdaInstanceOf() throws Exception {
@@ -26207,6 +26207,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/javaInterop/kt48590.kt");
}
@TestMetadata("kt65482.kt")
public void testKt65482() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/kt65482.kt");
}
@TestMetadata("lambdaInstanceOf.kt")
public void testLambdaInstanceOf() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt");