Complex augmented assignment test.

Fix string literal creation for empty string template.
This commit is contained in:
Dmitry Petrov
2016-08-17 12:09:12 +03:00
committed by Dmitry Petrov
parent 64d7a97145
commit c1583c4368
8 changed files with 55 additions and 14 deletions
@@ -145,15 +145,19 @@ class IrStatementGenerator(
}
override fun visitStringTemplateExpression(expression: KtStringTemplateExpression, data: Nothing?): IrStatement {
if (expression.entries.size == 1) {
val entry0 = expression.entries[0]
if (entry0 is KtLiteralStringTemplateEntry) {
return entry0.genExpr()
val entries = expression.entries
when {
entries.size == 1 -> {
val entry0 = entries[0]
if (entry0 is KtLiteralStringTemplateEntry) {
return entry0.genExpr()
}
}
entries.size == 0 -> return IrLiteralExpressionImpl.string(expression.startOffset, expression.endOffset, getInferredTypeWithSmarcastsOrFail(expression), "")
}
val irStringTemplate = IrStringConcatenationExpressionImpl(expression.startOffset, expression.endOffset, getInferredTypeWithSmartcasts(expression))
expression.entries.forEach { it.expression!!.let {
entries.forEach { it.expression!!.let {
irStringTemplate.addArgument(TODO())
} }
return irStringTemplate
@@ -91,7 +91,8 @@ abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() {
}
if (treeFiles.isEmpty()) {
treeFiles.add(IrTreeFileLabel(File(dir, testFile.name.replace(".kt", ".txt")), 0))
val file = createExpectedTextFile(testFile, dir, testFile.name.replace(".kt", ".txt"))
treeFiles.add(IrTreeFileLabel(file, 0))
}
return Expectations(regexps, treeFiles)
@@ -1,4 +1,4 @@
IrFile /augmentedAssignmentArray.kt
IrFile /arrayAugmentedAssignment1.kt
IrFunction public fun foo(): kotlin.IntArray
IrExpressionBody
BLOCK type=<no-type> hasResult=false isDesugared=true
@@ -0,0 +1,11 @@
interface IA {
operator fun get(index: String): Int
}
interface IB {
operator fun IA.set(index: String, value: Int)
}
fun IB.test(a: IA) {
a[""] += 42
}
@@ -0,0 +1,19 @@
IrFile /arrayAugmentedAssignment2.kt
DUMMY IA
DUMMY IB
IrFunction public fun IB.test(/*0*/ a: IA): kotlin.Unit
IrExpressionBody
BLOCK type=<no-type> hasResult=false isDesugared=false
VAR val tmp0_array: IA
GET_VAR a type=IA
VAR val tmp1_index0: kotlin.String
LITERAL String type=kotlin.String value=''
CALL .set type=kotlin.Unit operator=PLUSEQ
$this: $RECEIVER of: test type=IB
$receiver: GET_VAR tmp0_array type=IA
index: GET_VAR tmp1_index0 type=kotlin.String
value: CALL .plus type=kotlin.Int operator=PLUSEQ
$this: CALL .get type=kotlin.Int operator=PLUSEQ
$this: GET_VAR tmp0_array type=IA
index: GET_VAR tmp1_index0 type=kotlin.String
other: LITERAL Int type=kotlin.Int value='42'
@@ -10,7 +10,7 @@ IrFile /smartCastsWithDestructuring.kt
IrExpressionBody
BLOCK type=<no-type> hasResult=false isDesugared=true
RETURN type=<no-type>
? IrStringConcatenationExpressionImpl type=kotlin.String
LITERAL String type=kotlin.String value=''
IrFunction public fun test(/*0*/ x: I1): kotlin.Unit
IrExpressionBody
BLOCK type=<no-type> hasResult=false isDesugared=false
@@ -41,6 +41,18 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
doTest(fileName);
}
@TestMetadata("arrayAugmentedAssignment1.kt")
public void testArrayAugmentedAssignment1() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/arrayAugmentedAssignment1.kt");
doTest(fileName);
}
@TestMetadata("arrayAugmentedAssignment2.kt")
public void testArrayAugmentedAssignment2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/arrayAugmentedAssignment2.kt");
doTest(fileName);
}
@TestMetadata("assignments.kt")
public void testAssignments() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/assignments.kt");
@@ -59,12 +71,6 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
doTest(fileName);
}
@TestMetadata("augmentedAssignmentArray.kt")
public void testAugmentedAssignmentArray() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/augmentedAssignmentArray.kt");
doTest(fileName);
}
@TestMetadata("boxOk.kt")
public void testBoxOk() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/boxOk.kt");