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 2072807b214..5b35dc20f8f 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 @@ -18429,6 +18429,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr runTest("compiler/testData/codegen/box/fir/delegatedAndDataTogether.kt"); } + @Test + @TestMetadata("deserializedOptInDeprecated.kt") + public void testDeserializedOptInDeprecated() throws Exception { + runTest("compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt"); + } + @Test @TestMetadata("differentSinceKotlin.kt") public void testDifferentSinceKotlin() throws Exception { 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 c5f49e720ac..ca7a1d9f988 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 @@ -18429,6 +18429,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo runTest("compiler/testData/codegen/box/fir/delegatedAndDataTogether.kt"); } + @Test + @TestMetadata("deserializedOptInDeprecated.kt") + public void testDeserializedOptInDeprecated() throws Exception { + runTest("compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt"); + } + @Test @TestMetadata("differentSinceKotlin.kt") public void testDifferentSinceKotlin() throws Exception { diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/deprecationUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/deprecationUtils.kt index 3fc1e09e4bf..4aa6f9d8117 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/deprecationUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/deprecationUtils.kt @@ -103,7 +103,7 @@ fun FirAnnotationContainer.extractDeprecationInfoPerUseSite( ): DeprecationAnnotationInfoPerUseSiteStorage { val fromJava = this is FirDeclaration && this.isJavaOrEnhancement return buildDeprecationAnnotationInfoPerUseSiteStorage { - add((customAnnotations ?: annotations).extractDeprecationAnnotationInfoPerUseSite(session, fromJava)) + add((customAnnotations ?: annotations).extractDeprecationAnnotationInfoPerUseSite(fromJava)) if (this@extractDeprecationInfoPerUseSite is FirProperty) { add( getDeprecationsAnnotationInfoByUseSiteFromAccessors( @@ -158,7 +158,7 @@ fun List.getDeprecationsProviderFromAnnotations( session: FirSession, fromJava: Boolean ): DeprecationsProvider { - val deprecationAnnotationByUseSite = extractDeprecationAnnotationInfoPerUseSite(session, fromJava) + val deprecationAnnotationByUseSite = extractDeprecationAnnotationInfoPerUseSite(fromJava) return deprecationAnnotationByUseSite.toDeprecationsProvider(session.firCachesFactory) } @@ -199,9 +199,7 @@ val deprecationAnnotationSimpleNames: Set = setOf( StandardClassIds.Annotations.SinceKotlin.shortClassName.asString(), ) -private fun List.extractDeprecationAnnotationInfoPerUseSite( - session: FirSession, fromJava: Boolean -): DeprecationAnnotationInfoPerUseSiteStorage { +private fun List.extractDeprecationAnnotationInfoPerUseSite(fromJava: Boolean): DeprecationAnnotationInfoPerUseSiteStorage { // NB: We can't expand typealiases (`toAnnotationClassId`), because it // requires `lookupTag.tySymbol()`, but we can have cycles in annotations. // See the commit message for an example. @@ -228,9 +226,9 @@ private fun List.extractDeprecationAnnotationInfoPerUseSite( } else { val deprecationLevel = deprecated.getDeprecationLevel() ?: DeprecationLevelValue.WARNING val propagatesToOverride = !fromJavaAnnotation && !fromJava - val deprecatedSinceKotlin = getAnnotationsByClassId( - StandardClassIds.Annotations.DeprecatedSinceKotlin, session - ).firstOrNull() + val deprecatedSinceKotlin = this@extractDeprecationAnnotationInfoPerUseSite.firstOrNull { + it.unexpandedClassId == StandardClassIds.Annotations.DeprecatedSinceKotlin + } val message = deprecated.getStringArgument(ParameterNames.deprecatedMessage) val deprecatedInfo = diff --git a/compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt b/compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt new file mode 100644 index 00000000000..e6e70cdfca0 --- /dev/null +++ b/compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt @@ -0,0 +1,21 @@ +// MODULE: sub +// FILE: sub.kt +package foo + +class Base { + @RequiresOptIn + annotation class My + + @My + @Deprecated("Yes") + fun test() = "OK" +} + +// MODULE: dep(sub) +// FILE: box.kt +package some + +import foo.Base + +@OptIn(Base.My::class) +fun box() = Base().test() 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 5764f4fa40a..b883a21882f 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 @@ -17631,6 +17631,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/fir/ConstValAccess.kt"); } + @Test + @TestMetadata("deserializedOptInDeprecated.kt") + public void testDeserializedOptInDeprecated() throws Exception { + runTest("compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt"); + } + @Test @TestMetadata("differentSinceKotlin.kt") public void testDifferentSinceKotlin() throws Exception { 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 72c2261467c..51fa747ec36 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 @@ -18429,6 +18429,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/fir/delegatedAndDataTogether.kt"); } + @Test + @TestMetadata("deserializedOptInDeprecated.kt") + public void testDeserializedOptInDeprecated() throws Exception { + runTest("compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt"); + } + @Test @TestMetadata("differentSinceKotlin.kt") public void testDifferentSinceKotlin() throws Exception { 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 495982da1cb..94cf84b605b 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 @@ -18429,6 +18429,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack runTest("compiler/testData/codegen/box/fir/delegatedAndDataTogether.kt"); } + @Test + @TestMetadata("deserializedOptInDeprecated.kt") + public void testDeserializedOptInDeprecated() throws Exception { + runTest("compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt"); + } + @Test @TestMetadata("differentSinceKotlin.kt") public void testDifferentSinceKotlin() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 656163748e8..0d6fd02b594 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -14643,6 +14643,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/fir/ConstValAccess.kt"); } + @TestMetadata("deserializedOptInDeprecated.kt") + public void testDeserializedOptInDeprecated() throws Exception { + runTest("compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt"); + } + @TestMetadata("differentSinceKotlin.kt") public void testDifferentSinceKotlin() throws Exception { runTest("compiler/testData/codegen/box/fir/differentSinceKotlin.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index c78a3a0df19..3ec95b3e9ec 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -13659,6 +13659,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/fir/classCanNotBeCastedToVoid.kt"); } + @Test + @TestMetadata("deserializedOptInDeprecated.kt") + public void testDeserializedOptInDeprecated() throws Exception { + runTest("compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt"); + } + @Test @TestMetadata("falsePositiveBoundSmartcast.kt") public void testFalsePositiveBoundSmartcast() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java index 15a0caa54d7..22e84659b82 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java @@ -13761,6 +13761,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest { runTest("compiler/testData/codegen/box/fir/classCanNotBeCastedToVoid.kt"); } + @Test + @TestMetadata("deserializedOptInDeprecated.kt") + public void testDeserializedOptInDeprecated() throws Exception { + runTest("compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt"); + } + @Test @TestMetadata("falsePositiveBoundSmartcast.kt") public void testFalsePositiveBoundSmartcast() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index 574567c4483..d250703c2a8 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -13761,6 +13761,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/fir/classCanNotBeCastedToVoid.kt"); } + @Test + @TestMetadata("deserializedOptInDeprecated.kt") + public void testDeserializedOptInDeprecated() throws Exception { + runTest("compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt"); + } + @Test @TestMetadata("falsePositiveBoundSmartcast.kt") public void testFalsePositiveBoundSmartcast() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java index 53396bf353c..5a1e7434844 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java @@ -13761,6 +13761,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes runTest("compiler/testData/codegen/box/fir/classCanNotBeCastedToVoid.kt"); } + @Test + @TestMetadata("deserializedOptInDeprecated.kt") + public void testDeserializedOptInDeprecated() throws Exception { + runTest("compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt"); + } + @Test @TestMetadata("falsePositiveBoundSmartcast.kt") public void testFalsePositiveBoundSmartcast() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java index 28292cc4454..d101bc541ca 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java @@ -14942,6 +14942,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe runTest("compiler/testData/codegen/box/fir/classCanNotBeCastedToVoid.kt"); } + @Test + @TestMetadata("deserializedOptInDeprecated.kt") + public void testDeserializedOptInDeprecated() throws Exception { + runTest("compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt"); + } + @Test @TestMetadata("falsePositiveBoundSmartcast.kt") public void testFalsePositiveBoundSmartcast() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java index 99a561e3421..d88448a2511 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java @@ -15292,6 +15292,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB runTest("compiler/testData/codegen/box/fir/classCanNotBeCastedToVoid.kt"); } + @Test + @TestMetadata("deserializedOptInDeprecated.kt") + public void testDeserializedOptInDeprecated() throws Exception { + runTest("compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt"); + } + @Test @TestMetadata("falsePositiveBoundSmartcast.kt") public void testFalsePositiveBoundSmartcast() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index 2e00e878e0f..5788cdb6ce3 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -14768,6 +14768,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/fir/classCanNotBeCastedToVoid.kt"); } + @Test + @TestMetadata("deserializedOptInDeprecated.kt") + public void testDeserializedOptInDeprecated() throws Exception { + runTest("compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt"); + } + @Test @TestMetadata("falsePositiveBoundSmartcast.kt") public void testFalsePositiveBoundSmartcast() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java index 35dc28c0a4a..8227298e564 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java @@ -14943,6 +14943,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT runTest("compiler/testData/codegen/box/fir/classCanNotBeCastedToVoid.kt"); } + @Test + @TestMetadata("deserializedOptInDeprecated.kt") + public void testDeserializedOptInDeprecated() throws Exception { + runTest("compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt"); + } + @Test @TestMetadata("falsePositiveBoundSmartcast.kt") public void testFalsePositiveBoundSmartcast() throws Exception { diff --git a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java index 6dc38c6d99f..f2f0f3ffc83 100644 --- a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java +++ b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java @@ -12208,6 +12208,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/fir/classCanNotBeCastedToVoid.kt"); } + @TestMetadata("deserializedOptInDeprecated.kt") + public void testDeserializedOptInDeprecated() throws Exception { + runTest("compiler/testData/codegen/box/fir/deserializedOptInDeprecated.kt"); + } + @TestMetadata("falsePositiveBoundSmartcast.kt") public void testFalsePositiveBoundSmartcast() throws Exception { runTest("compiler/testData/codegen/box/fir/falsePositiveBoundSmartcast.kt");