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 3aa0f19d4d7..59af22ab08f 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 @@ -19053,6 +19053,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr runTest("compiler/testData/codegen/box/fir/KotlinDocumentationProvider.kt"); } + @Test + @TestMetadata("kt61856.kt") + public void testKt61856() throws Exception { + runTest("compiler/testData/codegen/box/fir/kt61856.kt"); + } + @Test @TestMetadata("linkViaSignatures.kt") public void testLinkViaSignatures() throws Exception { 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 c6a03c456f9..e4a5b64ad5f 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 @@ -19053,6 +19053,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated runTest("compiler/testData/codegen/box/fir/KotlinDocumentationProvider.kt"); } + @Test + @TestMetadata("kt61856.kt") + public void testKt61856() throws Exception { + runTest("compiler/testData/codegen/box/fir/kt61856.kt"); + } + @Test @TestMetadata("linkViaSignatures.kt") public void testLinkViaSignatures() 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 a1f222d2d8c..2a946d9bcd9 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 @@ -19053,6 +19053,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo runTest("compiler/testData/codegen/box/fir/KotlinDocumentationProvider.kt"); } + @Test + @TestMetadata("kt61856.kt") + public void testKt61856() throws Exception { + runTest("compiler/testData/codegen/box/fir/kt61856.kt"); + } + @Test @TestMetadata("linkViaSignatures.kt") public void testLinkViaSignatures() throws Exception { diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/AnnotationsLoader.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/AnnotationsLoader.kt index 7ed0b528d0b..95a09513dfa 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/AnnotationsLoader.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/AnnotationsLoader.kt @@ -7,13 +7,18 @@ package org.jetbrains.kotlin.fir.java.deserialization import org.jetbrains.kotlin.SpecialJvmAnnotations import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.isJavaOrEnhancement import org.jetbrains.kotlin.fir.deserialization.toQualifiedPropertyAccessExpression import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.builder.* import org.jetbrains.kotlin.fir.java.createConstantOrError import org.jetbrains.kotlin.fir.languageVersionSettings -import org.jetbrains.kotlin.fir.resolve.providers.getClassDeclaredPropertySymbols +import org.jetbrains.kotlin.fir.resolve.ScopeSession +import org.jetbrains.kotlin.fir.resolve.providers.getRegularClassSymbolByClassId import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider +import org.jetbrains.kotlin.fir.scopes.getProperties +import org.jetbrains.kotlin.fir.scopes.impl.declaredMemberScope +import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef @@ -130,6 +135,7 @@ internal class AnnotationsLoader(private val session: FirSession, private val ko return object : AnnotationsLoaderVisitorImpl(enumEntryReferenceCreator) { private val argumentMap = mutableMapOf() + private val scopeSession: ScopeSession = ScopeSession() override fun visitExpression(name: Name?, expr: FirExpression) { if (name != null) argumentMap[name] = expr @@ -143,7 +149,15 @@ internal class AnnotationsLoader(private val session: FirSession, private val ko if (name == null) return null // Note: generally we are not allowed to resolve anything, as this is might lead to recursive resolve problems // However, K1 deserializer did exactly the same and no issues were reported. - val propS = session.symbolProvider.getClassDeclaredPropertySymbols(annotationClassId, name).firstOrNull() + val classSymbol = session.symbolProvider.getRegularClassSymbolByClassId(annotationClassId) ?: return null + // We need to enhance java classes, but we can't call unsubstitutedScope unconditionally because + // for Kotlin types, it will resolve the class to the SUPER_TYPES phase which can lead to a contract violation. + val scope = if (classSymbol.isJavaOrEnhancement) { + classSymbol.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false, memberRequiredPhase = null) + } else { + classSymbol.declaredMemberScope(session, memberRequiredPhase = null) + } + val propS = scope.getProperties(name).firstOrNull() return propS?.resolvedReturnTypeRef } diff --git a/compiler/testData/codegen/box/fir/kt61856.kt b/compiler/testData/codegen/box/fir/kt61856.kt new file mode 100644 index 00000000000..6db9ff1aa60 --- /dev/null +++ b/compiler/testData/codegen/box/fir/kt61856.kt @@ -0,0 +1,34 @@ +// TARGET_BACKEND: JVM_IR +// WITH_STDLIB +// MODULE: a +// FILE: Email.java +package javax.validation.constraints; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE}) +@Retention(java.lang.annotation.RetentionPolicy.RUNTIME) +public @interface Email { + @Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE}) + @Retention(RetentionPolicy.RUNTIME) + public @interface List { + Email[] value(); + } +} + +// FILE: a.kt +import javax.validation.constraints.Email + +class BoardContentLogController { + fun getBoardContentItemLogs(@Email.List emails: List) {} +} + +// MODULE: box(a) +// FILE: box.kt +fun box(): String { + BoardContentLogController().getBoardContentItemLogs(listOf("email1", "email2")) + return "OK" +} \ No newline at end of file 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 6375389a32d..45ec0333f8a 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 @@ -19053,6 +19053,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/fir/KotlinDocumentationProvider.kt"); } + @Test + @TestMetadata("kt61856.kt") + public void testKt61856() throws Exception { + runTest("compiler/testData/codegen/box/fir/kt61856.kt"); + } + @Test @TestMetadata("linkViaSignatures.kt") public void testLinkViaSignatures() 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 150d269d9fc..91894be3f95 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 @@ -19053,6 +19053,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack runTest("compiler/testData/codegen/box/fir/KotlinDocumentationProvider.kt"); } + @Test + @TestMetadata("kt61856.kt") + public void testKt61856() throws Exception { + runTest("compiler/testData/codegen/box/fir/kt61856.kt"); + } + @Test @TestMetadata("linkViaSignatures.kt") public void testLinkViaSignatures() 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 2260835c916..c39ea0b8f5c 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -15866,6 +15866,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/fir/KotlinDocumentationProvider.kt"); } + @TestMetadata("kt61856.kt") + public void testKt61856() throws Exception { + runTest("compiler/testData/codegen/box/fir/kt61856.kt"); + } + @TestMetadata("linkViaSignatures.kt") public void testLinkViaSignatures() throws Exception { runTest("compiler/testData/codegen/box/fir/linkViaSignatures.kt");