[K2] Forbid to use "get class" in the context of string concat and equality
#KT-63941 Fixed
This commit is contained in:
+12
@@ -23693,6 +23693,18 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/kCallable_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kClassInEquals.kt")
|
||||
public void testKClassInEquals() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/kClassInEquals.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kClassInStringConcatenation.kt")
|
||||
public void testKClassInStringConcatenation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/kClassInStringConcatenation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kotlinJavaCycle.kt")
|
||||
public void testKotlinJavaCycle() throws Exception {
|
||||
|
||||
+12
@@ -23693,6 +23693,18 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/kCallable_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kClassInEquals.kt")
|
||||
public void testKClassInEquals() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/kClassInEquals.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kClassInStringConcatenation.kt")
|
||||
public void testKClassInStringConcatenation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/kClassInStringConcatenation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kotlinJavaCycle.kt")
|
||||
public void testKotlinJavaCycle() throws Exception {
|
||||
|
||||
+12
@@ -23687,6 +23687,18 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/kCallable_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kClassInEquals.kt")
|
||||
public void testKClassInEquals() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/kClassInEquals.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kClassInStringConcatenation.kt")
|
||||
public void testKClassInStringConcatenation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/kClassInStringConcatenation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kotlinJavaCycle.kt")
|
||||
public void testKotlinJavaCycle() throws Exception {
|
||||
|
||||
+12
@@ -23693,6 +23693,18 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/kCallable_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kClassInEquals.kt")
|
||||
public void testKClassInEquals() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/kClassInEquals.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kClassInStringConcatenation.kt")
|
||||
public void testKClassInStringConcatenation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/kClassInStringConcatenation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kotlinJavaCycle.kt")
|
||||
public void testKotlinJavaCycle() throws Exception {
|
||||
|
||||
+7
-2
@@ -85,7 +85,7 @@ internal fun checkConstantArguments(
|
||||
}
|
||||
expression is FirStringConcatenationCall -> {
|
||||
for (exp in (expression as FirCall).arguments) {
|
||||
if (exp is FirResolvedQualifier || expression.isForbiddenComplexConstant(session)) {
|
||||
if (exp is FirResolvedQualifier || exp is FirGetClassCall) {
|
||||
return ConstantArgumentKind.NOT_CONST
|
||||
}
|
||||
checkConstantArguments(exp, session)?.let { return it }
|
||||
@@ -95,8 +95,13 @@ internal fun checkConstantArguments(
|
||||
if (expression.operation == FirOperation.IDENTITY || expression.operation == FirOperation.NOT_IDENTITY) {
|
||||
return ConstantArgumentKind.NOT_CONST
|
||||
}
|
||||
|
||||
if (expression.isForbiddenComplexConstant(session)) {
|
||||
return ConstantArgumentKind.NOT_CONST
|
||||
}
|
||||
|
||||
for (exp in (expression as FirCall).arguments) {
|
||||
if (exp is FirResolvedQualifier || expression.isForbiddenComplexConstant(session) || exp.getExpandedType().isUnsignedType) {
|
||||
if (exp is FirResolvedQualifier || exp is FirGetClassCall || exp.getExpandedType().isUnsignedType) {
|
||||
return ConstantArgumentKind.NOT_CONST
|
||||
}
|
||||
checkConstantArguments(exp, session)?.let { return it }
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// FIR_IDENTICAL
|
||||
annotation class Anno(val equal: Boolean)
|
||||
|
||||
class A
|
||||
class B
|
||||
|
||||
@Anno(<!ANNOTATION_ARGUMENT_MUST_BE_CONST!>A::class == B::class<!>)
|
||||
class C
|
||||
|
||||
const val equal = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>A::class == B::class<!>
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// FIR_IDENTICAL
|
||||
annotation class Anno(val str: String)
|
||||
|
||||
@Anno(<!ANNOTATION_ARGUMENT_MUST_BE_CONST!>"${A::class}"<!>)
|
||||
class A
|
||||
|
||||
@Anno(<!ANNOTATION_ARGUMENT_MUST_BE_CONST!>B::class.toString()<!>)
|
||||
class B
|
||||
|
||||
const val a = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>"${A::class}"<!>
|
||||
const val b = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>B::class.toString()<!>
|
||||
Generated
+12
@@ -23693,6 +23693,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/kCallable_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kClassInEquals.kt")
|
||||
public void testKClassInEquals() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/kClassInEquals.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kClassInStringConcatenation.kt")
|
||||
public void testKClassInStringConcatenation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/modifiers/const/kClassInStringConcatenation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kotlinJavaCycle.kt")
|
||||
public void testKotlinJavaCycle() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user