[K2] Support proper serialization of string concatenation expressions

This commit is contained in:
Ivan Kylchik
2023-04-05 15:10:53 +02:00
committed by Space Team
parent 1e3e04173b
commit 6909d9a2f9
7 changed files with 114 additions and 0 deletions
@@ -73,6 +73,12 @@ private abstract class FirToConstantValueTransformer(
}
}
override fun visitStringConcatenationCall(stringConcatenationCall: FirStringConcatenationCall, data: FirSession): ConstantValue<*>? {
val strings = stringConcatenationCall.argumentList.arguments.map { it.accept(this, data) }
if (strings.any { it == null || it !is StringValue }) return null
return StringValue(strings.joinToString(separator = "") { (it as StringValue).value })
}
override fun visitArrayOfCall(
arrayOfCall: FirArrayOfCall,
data: FirSession
@@ -208,6 +214,10 @@ internal object FirToConstantValueChecker : FirDefaultVisitor<Boolean, FirSessio
return constExpression.kind in supportedConstKinds
}
override fun visitStringConcatenationCall(stringConcatenationCall: FirStringConcatenationCall, data: FirSession): Boolean {
return stringConcatenationCall.argumentList.arguments.all { it.accept(this, data) }
}
override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: FirSession): Boolean {
return arrayOfCall.arguments.all { it.accept(this, data) }
}
@@ -0,0 +1,7 @@
object Obj {
const val O = "O"
val concat = "${O}K"
}
@Deprecated("${Obj.O}/{id}")
class Foo
@@ -0,0 +1,6 @@
package <root> {
@Deprecated(message = "O/{id}") class Foo constructor()
object Obj {
const val O: String = "O"
val concat: String = "OK"
}
@@ -24832,6 +24832,46 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
runTest("compiler/testData/codegen/box/involvesIrInterpreter/dumpIrAndCheck/unsignedConst.kt");
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/involvesIrInterpreter/serialization")
@TestDataPath("$PROJECT_ROOT")
@Tag("codegenK2")
@Tag("firCodegen")
@UseExtTestCaseGroupProvider()
@FirPipeline()
@UsePartialLinkage(mode = Mode.DISABLED)
@Tag("no-partial-linkage-may-be-skipped")
public class Serialization {
@Test
public void testAllFilesPresentInSerialization() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter/serialization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("annotationInArguments.kt")
public void testAnnotationInArguments() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/serialization/annotationInArguments.kt");
}
@Test
@TestMetadata("annotationSerialization.kt")
public void testAnnotationSerialization() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/serialization/annotationSerialization.kt");
}
@Test
@TestMetadata("annotationWithArray.kt")
public void testAnnotationWithArray() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/serialization/annotationWithArray.kt");
}
@Test
@TestMetadata("annotationWithDefaults.kt")
public void testAnnotationWithDefaults() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/serialization/annotationWithDefaults.kt");
}
}
}
@Nested
@@ -125,6 +125,12 @@ public class FirNativeKLibContentsTestGenerated extends AbstractNativeKlibConten
runTest("native/native.tests/testData/klibContents/builtinsSerializer/sourceRetainedAnnotation.kt");
}
@Test
@TestMetadata("stringConcatenation.kt")
public void testStringConcatenation() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/stringConcatenation.kt");
}
@Test
@TestMetadata("typeParameterAnnotation.kt")
public void testTypeParameterAnnotation() throws Exception {
@@ -24597,6 +24597,45 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
runTest("compiler/testData/codegen/box/involvesIrInterpreter/dumpIrAndCheck/unsignedConst.kt");
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/involvesIrInterpreter/serialization")
@TestDataPath("$PROJECT_ROOT")
@Tag("codegen")
@Tag("k1Codegen")
@UseExtTestCaseGroupProvider()
@UsePartialLinkage(mode = Mode.DISABLED)
@Tag("no-partial-linkage-may-be-skipped")
public class Serialization {
@Test
public void testAllFilesPresentInSerialization() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter/serialization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("annotationInArguments.kt")
public void testAnnotationInArguments() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/serialization/annotationInArguments.kt");
}
@Test
@TestMetadata("annotationSerialization.kt")
public void testAnnotationSerialization() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/serialization/annotationSerialization.kt");
}
@Test
@TestMetadata("annotationWithArray.kt")
public void testAnnotationWithArray() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/serialization/annotationWithArray.kt");
}
@Test
@TestMetadata("annotationWithDefaults.kt")
public void testAnnotationWithDefaults() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/serialization/annotationWithDefaults.kt");
}
}
}
@Nested
@@ -120,6 +120,12 @@ public class NativeKLibContentsTestGenerated extends AbstractNativeKlibContentsT
runTest("native/native.tests/testData/klibContents/builtinsSerializer/sourceRetainedAnnotation.kt");
}
@Test
@TestMetadata("stringConcatenation.kt")
public void testStringConcatenation() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/stringConcatenation.kt");
}
@Test
@TestMetadata("typeParameterAnnotation.kt")
public void testTypeParameterAnnotation() throws Exception {