[FIR] Don't crash on complex expression as annotation argument if metadata compilation is used
^KT-58139 Fixed
This commit is contained in:
committed by
Space Team
parent
abdb173f6c
commit
2251214d24
+14
-1
@@ -5,10 +5,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.serialization
|
||||
|
||||
import org.jetbrains.kotlin.config.AnalysisFlags
|
||||
import org.jetbrains.kotlin.constant.AnnotationValue
|
||||
import org.jetbrains.kotlin.constant.ConstantValue
|
||||
import org.jetbrains.kotlin.constant.ErrorValue
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.render
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.serialization.constant.ConstValueProvider
|
||||
@@ -50,7 +53,17 @@ class FirAnnotationSerializer(
|
||||
}
|
||||
|
||||
for ((name, argument) in argumentsMapping) {
|
||||
addArgument(argument, name)
|
||||
if (argument !is ErrorValue) {
|
||||
addArgument(argument, name)
|
||||
continue
|
||||
}
|
||||
|
||||
if (!session.languageVersionSettings.getFlag(AnalysisFlags.metadataCompilation)) {
|
||||
error(
|
||||
(argument as? ErrorValue.ErrorValueWithMessage)?.message
|
||||
?: "Error value after conversion of expression of $name argument"
|
||||
)
|
||||
}
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
|
||||
+7
@@ -5,18 +5,22 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.serialization.constant
|
||||
|
||||
import org.jetbrains.kotlin.config.AnalysisFlags
|
||||
import org.jetbrains.kotlin.constant.AnnotationValue
|
||||
import org.jetbrains.kotlin.constant.ConstantValue
|
||||
import org.jetbrains.kotlin.constant.ErrorValue
|
||||
import org.jetbrains.kotlin.constant.KClassValue
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.render
|
||||
import org.jetbrains.kotlin.fir.resolve.defaultType
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||
|
||||
internal fun Map<Name, FirExpression>.convertToConstantValues(
|
||||
session: FirSession,
|
||||
@@ -25,6 +29,9 @@ internal fun Map<Name, FirExpression>.convertToConstantValues(
|
||||
return this.map { (name, firExpression) ->
|
||||
val constantValue = constValueProvider?.findConstantValueFor(firExpression)
|
||||
?: firExpression.toConstantValue(session, constValueProvider)
|
||||
?: runIf(session.languageVersionSettings.getFlag(AnalysisFlags.metadataCompilation)) {
|
||||
ErrorValue.ErrorValueWithMessage("Constant conversion can be ignored in metadata compilation mode")
|
||||
}
|
||||
?: error("Cannot convert expression ${firExpression.render()} to constant")
|
||||
name to constantValue
|
||||
}.toMap()
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
$TESTDATA_DIR$/kt58139/common.kt
|
||||
$TESTDATA_DIR$/kt58139/platform.kt
|
||||
-Xcommon-sources=$TESTDATA_DIR$/kt58139/common.kt
|
||||
-language-version
|
||||
2.0
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
|
||||
OK
|
||||
@@ -0,0 +1,8 @@
|
||||
// ISSUE: KT-58139
|
||||
|
||||
annotation class AnnKlass(val arg: String)
|
||||
|
||||
@AnnKlass("lhs" + "rhs")
|
||||
fun foo() {}
|
||||
|
||||
const val BATCH_SIZE: Int = 16 * 1024
|
||||
@@ -0,0 +1,6 @@
|
||||
const val DOUBLE_BATCH_SIZE = 2 * BATCH_SIZE
|
||||
|
||||
annotation class A(val value: Int)
|
||||
|
||||
@A(BATCH_SIZE)
|
||||
fun bar() {}
|
||||
@@ -1599,6 +1599,11 @@ public class CliTestGenerated extends AbstractCliTest {
|
||||
runTest("compiler/testData/cli/metadata/kotlinPackageWithFir.args");
|
||||
}
|
||||
|
||||
@TestMetadata("kt58139.args")
|
||||
public void testKt58139() throws Exception {
|
||||
runTest("compiler/testData/cli/metadata/kt58139.args");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaWithReceiver.args")
|
||||
public void testLambdaWithReceiver() throws Exception {
|
||||
runTest("compiler/testData/cli/metadata/lambdaWithReceiver.args");
|
||||
|
||||
Reference in New Issue
Block a user