[FIR] KT-57835: Prevent the compiler crash
^KT-57835 Fixed
This commit is contained in:
committed by
Space Team
parent
e1c91ee50f
commit
caa7bee917
@@ -12,6 +12,7 @@ dependencies {
|
|||||||
|
|
||||||
api(project(":compiler:fir:cones"))
|
api(project(":compiler:fir:cones"))
|
||||||
api(project(":compiler:fir:tree"))
|
api(project(":compiler:fir:tree"))
|
||||||
|
api(project(":compiler:fir:java"))
|
||||||
api(project(":compiler:fir:providers"))
|
api(project(":compiler:fir:providers"))
|
||||||
api(project(":compiler:fir:semantics"))
|
api(project(":compiler:fir:semantics"))
|
||||||
api(project(":compiler:fir:resolve"))
|
api(project(":compiler:fir:resolve"))
|
||||||
|
|||||||
+14
@@ -9,9 +9,11 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
|||||||
import org.jetbrains.kotlin.fir.*
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirEnumEntry
|
import org.jetbrains.kotlin.fir.declarations.FirEnumEntry
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isConst
|
import org.jetbrains.kotlin.fir.declarations.utils.isConst
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.utils.isFinal
|
||||||
import org.jetbrains.kotlin.fir.expressions.*
|
import org.jetbrains.kotlin.fir.expressions.*
|
||||||
import org.jetbrains.kotlin.fir.expressions.builder.buildAnnotationArgumentMapping
|
import org.jetbrains.kotlin.fir.expressions.builder.buildAnnotationArgumentMapping
|
||||||
import org.jetbrains.kotlin.fir.expressions.builder.buildAnnotationCall
|
import org.jetbrains.kotlin.fir.expressions.builder.buildAnnotationCall
|
||||||
|
import org.jetbrains.kotlin.fir.java.declarations.FirJavaField
|
||||||
import org.jetbrains.kotlin.fir.references.builder.buildSimpleNamedReference
|
import org.jetbrains.kotlin.fir.references.builder.buildSimpleNamedReference
|
||||||
import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol
|
import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirArrayOfCallTransformer
|
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirArrayOfCallTransformer
|
||||||
@@ -109,6 +111,7 @@ private abstract class FirToConstantValueTransformer(
|
|||||||
data: FirSession
|
data: FirSession
|
||||||
): ConstantValue<*>? {
|
): ConstantValue<*>? {
|
||||||
val symbol = qualifiedAccessExpression.toResolvedCallableSymbol() ?: return null
|
val symbol = qualifiedAccessExpression.toResolvedCallableSymbol() ?: return null
|
||||||
|
val fir = symbol.fir
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
symbol.fir is FirEnumEntry -> {
|
symbol.fir is FirEnumEntry -> {
|
||||||
@@ -120,6 +123,14 @@ private abstract class FirToConstantValueTransformer(
|
|||||||
if (symbol.fir.isConst) symbol.fir.initializer?.accept(this, data) else null
|
if (symbol.fir.isConst) symbol.fir.initializer?.accept(this, data) else null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fir is FirJavaField -> {
|
||||||
|
if (fir.isFinal) {
|
||||||
|
fir.initializer?.accept(this, data)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
symbol is FirConstructorSymbol -> {
|
symbol is FirConstructorSymbol -> {
|
||||||
val constructorCall = qualifiedAccessExpression as FirFunctionCall
|
val constructorCall = qualifiedAccessExpression as FirFunctionCall
|
||||||
val constructedClassSymbol = symbol.containingClassLookupTag()?.toFirRegularClassSymbol(data) ?: return null
|
val constructedClassSymbol = symbol.containingClassLookupTag()?.toFirRegularClassSymbol(data) ?: return null
|
||||||
@@ -232,12 +243,15 @@ internal object FirToConstantValueChecker : FirDefaultVisitor<Boolean, FirSessio
|
|||||||
|
|
||||||
override fun visitQualifiedAccessExpression(qualifiedAccessExpression: FirQualifiedAccessExpression, data: FirSession): Boolean {
|
override fun visitQualifiedAccessExpression(qualifiedAccessExpression: FirQualifiedAccessExpression, data: FirSession): Boolean {
|
||||||
val symbol = qualifiedAccessExpression.toResolvedCallableSymbol() ?: return false
|
val symbol = qualifiedAccessExpression.toResolvedCallableSymbol() ?: return false
|
||||||
|
val fir = symbol.fir
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
symbol.fir is FirEnumEntry -> symbol.fir.returnTypeRef.coneTypeSafe<ConeClassLikeType>()?.classId != null
|
symbol.fir is FirEnumEntry -> symbol.fir.returnTypeRef.coneTypeSafe<ConeClassLikeType>()?.classId != null
|
||||||
|
|
||||||
symbol is FirPropertySymbol -> symbol.fir.isConst
|
symbol is FirPropertySymbol -> symbol.fir.isConst
|
||||||
|
|
||||||
|
fir is FirJavaField -> symbol.fir.isFinal
|
||||||
|
|
||||||
symbol is FirConstructorSymbol -> {
|
symbol is FirConstructorSymbol -> {
|
||||||
symbol.containingClassLookupTag()?.toFirRegularClassSymbol(data)?.classKind == ClassKind.ANNOTATION_CLASS
|
symbol.containingClassLookupTag()?.toFirRegularClassSymbol(data)?.classKind == ClassKind.ANNOTATION_CLASS
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -227,6 +227,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
|||||||
runTest("compiler/testData/codegen/box/annotations/javaAnnotationWithSingleArrayArgument.kt");
|
runTest("compiler/testData/codegen/box/annotations/javaAnnotationWithSingleArrayArgument.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("javaConstAnnotationArguments.kt")
|
||||||
|
public void testJavaConstAnnotationArguments() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/annotations/javaConstAnnotationArguments.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("javaNegativePropertyAsAnnotationParameter.kt")
|
@TestMetadata("javaNegativePropertyAsAnnotationParameter.kt")
|
||||||
public void testJavaNegativePropertyAsAnnotationParameter() throws Exception {
|
public void testJavaNegativePropertyAsAnnotationParameter() throws Exception {
|
||||||
|
|||||||
+6
@@ -227,6 +227,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
|||||||
runTest("compiler/testData/codegen/box/annotations/javaAnnotationWithSingleArrayArgument.kt");
|
runTest("compiler/testData/codegen/box/annotations/javaAnnotationWithSingleArrayArgument.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("javaConstAnnotationArguments.kt")
|
||||||
|
public void testJavaConstAnnotationArguments() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/annotations/javaConstAnnotationArguments.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("javaNegativePropertyAsAnnotationParameter.kt")
|
@TestMetadata("javaNegativePropertyAsAnnotationParameter.kt")
|
||||||
public void testJavaNegativePropertyAsAnnotationParameter() throws Exception {
|
public void testJavaNegativePropertyAsAnnotationParameter() throws Exception {
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// ISSUE: KT-57879
|
||||||
|
// TARGET_BACKEND: JVM_IR
|
||||||
|
|
||||||
|
// FILE: CoreBundle.java
|
||||||
|
|
||||||
|
public class CoreBundle {
|
||||||
|
public static final String BUNDLE = "OK";
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.TYPE)
|
||||||
|
annotation class AnnKlass(val argument: String)
|
||||||
|
|
||||||
|
fun message(key: @AnnKlass(CoreBundle.BUNDLE) String) = key
|
||||||
|
|
||||||
|
fun box() = message("OK")
|
||||||
+6
@@ -227,6 +227,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/annotations/javaAnnotationWithSingleArrayArgument.kt");
|
runTest("compiler/testData/codegen/box/annotations/javaAnnotationWithSingleArrayArgument.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("javaConstAnnotationArguments.kt")
|
||||||
|
public void testJavaConstAnnotationArguments() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/annotations/javaConstAnnotationArguments.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("javaNegativePropertyAsAnnotationParameter.kt")
|
@TestMetadata("javaNegativePropertyAsAnnotationParameter.kt")
|
||||||
public void testJavaNegativePropertyAsAnnotationParameter() throws Exception {
|
public void testJavaNegativePropertyAsAnnotationParameter() throws Exception {
|
||||||
|
|||||||
+6
@@ -227,6 +227,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
|||||||
runTest("compiler/testData/codegen/box/annotations/javaAnnotationWithSingleArrayArgument.kt");
|
runTest("compiler/testData/codegen/box/annotations/javaAnnotationWithSingleArrayArgument.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("javaConstAnnotationArguments.kt")
|
||||||
|
public void testJavaConstAnnotationArguments() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/annotations/javaConstAnnotationArguments.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("javaNegativePropertyAsAnnotationParameter.kt")
|
@TestMetadata("javaNegativePropertyAsAnnotationParameter.kt")
|
||||||
public void testJavaNegativePropertyAsAnnotationParameter() throws Exception {
|
public void testJavaNegativePropertyAsAnnotationParameter() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user