[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.
diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java index c5d9ad3..b13af37 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java
@@ -31221,6 +31221,12 @@ } @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 { runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt");
diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java index 73d3bd3..3346a1f 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java
@@ -31221,6 +31221,12 @@ } @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 { runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt");
diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java index 2185378..97b4e62 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java
@@ -30890,6 +30890,12 @@ } @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 { runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt");
diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java index d447359..a60c9a5 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java
@@ -30890,6 +30890,12 @@ } @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 { runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt");
diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java index 3975238..34a87ea 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java
@@ -30890,6 +30890,12 @@ } @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 { runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt");
diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/SignatureEnhancement.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/SignatureEnhancement.kt index 152f14b..c001d69 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/SignatureEnhancement.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/SignatureEnhancement.kt
@@ -632,10 +632,19 @@ 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 @@ containerApplicabilityType, TypeInSignature.Return, predefinedEnhancementInfo?.returnTypeInfo, - forAnnotationMember = this.owner.classKind == ClassKind.ANNOTATION_CLASS + forAnnotationMember = forAnnotationMember ) }
diff --git a/compiler/testData/codegen/box/javaInterop/kt65482.kt b/compiler/testData/codegen/box/javaInterop/kt65482.kt new file mode 100644 index 0000000..be26417 --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/kt65482.kt
@@ -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" +}
diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java index 9fb5c93..82c3e26 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java
@@ -30890,6 +30890,12 @@ } @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 { runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt");
diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 3c39787..4750c2d 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java
@@ -29096,6 +29096,12 @@ } @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 { runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt");
diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 5255c3b..b86fc9f 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java
@@ -30890,6 +30890,12 @@ } @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 { runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt");
diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java index 9f9297e..c696394 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java
@@ -30890,6 +30890,12 @@ } @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 { runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt");
diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 8af2c2c..93cbbbb 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java
@@ -26172,6 +26172,11 @@ 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");