[FIR] KT-53435: Fix false positive ANNOTATION_ARGUMENT_MUST_BE_CONST

Otherwise, `FirNamedArgumentExpression` are not considered
const expr despite the value.

Merge-request: KT-MR-7052
Merged-by: Nikolay Lunyak <lunyak.kolya@mail.ru>
This commit is contained in:
Nikolay Lunyak
2022-09-07 12:34:26 +00:00
committed by Space
parent ff1adf596d
commit 45619ab390
7 changed files with 83 additions and 0 deletions
@@ -404,6 +404,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis
runTest("compiler/fir/analysis-tests/testData/resolve/localObject.kt");
}
@Test
@TestMetadata("nestedAnnotationConstExprArguments.kt")
public void testNestedAnnotationConstExprArguments() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/nestedAnnotationConstExprArguments.kt");
}
@Test
@TestMetadata("nestedClass.kt")
public void testNestedClass() throws Exception {
@@ -344,6 +344,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
runTest("compiler/fir/analysis-tests/testData/resolve/localObject.kt");
}
@TestMetadata("nestedAnnotationConstExprArguments.kt")
public void testNestedAnnotationConstExprArguments() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/nestedAnnotationConstExprArguments.kt");
}
@TestMetadata("nestedClass.kt")
public void testNestedClass() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/nestedClass.kt");
@@ -0,0 +1,43 @@
FILE: nestedAnnotationConstExprArguments.kt
public final annotation class InnerAnnotation : R|kotlin/Annotation| {
public constructor(text: R|kotlin/String|): R|InnerAnnotation| {
super<R|kotlin/Any|>()
}
public final val text: R|kotlin/String| = R|<local>/text|
public get(): R|kotlin/String|
}
public final annotation class OuterAnnotation : R|kotlin/Annotation| {
public constructor(inner: R|InnerAnnotation|): R|OuterAnnotation| {
super<R|kotlin/Any|>()
}
public final val inner: R|InnerAnnotation| = R|<local>/inner|
public get(): R|InnerAnnotation|
}
@R|OuterAnnotation|(inner = R|/InnerAnnotation.InnerAnnotation|(text = String(x).R|kotlin/String.plus|(String(x)))) public final class Payload : R|kotlin/Any| {
public constructor(): R|Payload| {
super<R|kotlin/Any|>()
}
}
@R|InnerAnnotation|(text = String(x).R|kotlin/String.plus|(String(x))) public final class Payload2 : R|kotlin/Any| {
public constructor(): R|Payload2| {
super<R|kotlin/Any|>()
}
}
@R|OuterAnnotation|(inner = R|/InnerAnnotation.InnerAnnotation|(text = String(x))) public final class Payload3 : R|kotlin/Any| {
public constructor(): R|Payload3| {
super<R|kotlin/Any|>()
}
}
@R|OuterAnnotation|(inner = R|/InnerAnnotation.InnerAnnotation|(String(x).R|kotlin/String.plus|(String(x)))) public final class Payload4 : R|kotlin/Any| {
public constructor(): R|Payload4| {
super<R|kotlin/Any|>()
}
}
@@ -0,0 +1,14 @@
annotation class InnerAnnotation(val text: String)
annotation class OuterAnnotation(val inner: InnerAnnotation)
@OuterAnnotation(InnerAnnotation(text = "x" + "x"))
class Payload
@InnerAnnotation(text = "x" + "x")
class Payload2
@OuterAnnotation(InnerAnnotation(text = "x"))
class Payload3
@OuterAnnotation(InnerAnnotation("x" + "x"))
class Payload4
@@ -404,6 +404,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
runTest("compiler/fir/analysis-tests/testData/resolve/localObject.kt");
}
@Test
@TestMetadata("nestedAnnotationConstExprArguments.kt")
public void testNestedAnnotationConstExprArguments() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/nestedAnnotationConstExprArguments.kt");
}
@Test
@TestMetadata("nestedClass.kt")
public void testNestedClass() throws Exception {
@@ -404,6 +404,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/analysis-tests/testData/resolve/localObject.kt");
}
@Test
@TestMetadata("nestedAnnotationConstExprArguments.kt")
public void testNestedAnnotationConstExprArguments() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/nestedAnnotationConstExprArguments.kt");
}
@Test
@TestMetadata("nestedClass.kt")
public void testNestedClass() throws Exception {
@@ -34,6 +34,9 @@ internal fun checkConstantArguments(
?.classKind
when {
expression is FirNamedArgumentExpression -> {
checkConstantArguments(expression.expression, session)
}
expression is FirTypeOperatorCall -> if (expression.operation == FirOperation.AS) return ConstantArgumentKind.NOT_CONST
expression is FirWhenExpression -> {
if (!expression.isProperlyExhaustive) {