[FIR] Use enhanced scope to guess array type in annotation loading
Otherwise, we return null for any java annotation because the unenhanced scope doesn't contain any properties. #KT-61856 Fixed
This commit is contained in:
committed by
Space Team
parent
c4da53475e
commit
2e4d486131
+6
@@ -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 {
|
||||
|
||||
+6
@@ -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 {
|
||||
|
||||
+6
@@ -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 {
|
||||
|
||||
+16
-2
@@ -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<Name, FirExpression>()
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
+34
@@ -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<String>) {}
|
||||
}
|
||||
|
||||
// MODULE: box(a)
|
||||
// FILE: box.kt
|
||||
fun box(): String {
|
||||
BoardContentLogController().getBoardContentItemLogs(listOf("email1", "email2"))
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -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 {
|
||||
|
||||
+6
@@ -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 {
|
||||
|
||||
+5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user