KT-13160: when decomposing assignment with lhs like array[index], extract array instead of supporting only qualifier.name`
This commit is contained in:
@@ -183,10 +183,18 @@ internal class ExpressionDecomposer private constructor(
|
||||
}
|
||||
|
||||
if (operator.isAssignment) {
|
||||
// Must be (someThingWithSideEffect).x = arg2, because arg1 can have side effect
|
||||
assert(arg1 is JsNameRef) { "Valid JavaScript left-hand side must be JsNameRef, got: $this" }
|
||||
val arg1AsRef = arg1 as JsNameRef
|
||||
arg1AsRef.qualifier = arg1AsRef.qualifier?.extractToTemporary()
|
||||
val lhs = arg1
|
||||
when (lhs) {
|
||||
is JsNameRef -> {
|
||||
lhs.qualifier = lhs.qualifier?.extractToTemporary()
|
||||
}
|
||||
is JsArrayAccess -> {
|
||||
lhs.array = lhs.array.extractToTemporary()
|
||||
}
|
||||
else -> {
|
||||
error("Valid JavaScript left-hand side must be either JsNameRef or JsArrayAccess, got: $this")
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
arg1 = arg1.extractToTemporary()
|
||||
|
||||
+6
@@ -77,6 +77,12 @@ public class InlineEvaluationOrderTestGenerated extends AbstractInlineEvaluation
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("arrayAccessLhsDecomposed.kt")
|
||||
public void testArrayAccessLhsDecomposed() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/inlineEvaluationOrder/cases/arrayAccessLhsDecomposed.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("arrayLiteral.kt")
|
||||
public void testArrayLiteral() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/inlineEvaluationOrder/cases/arrayLiteral.kt");
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package foo
|
||||
|
||||
var global = ""
|
||||
|
||||
class A(val data: Array<Int>)
|
||||
|
||||
fun box(): String {
|
||||
val a = A(arrayOf(1, 2, 3))
|
||||
a.data[0] = listOf(1, 2, 3).fold(0) { a, b ->
|
||||
global += "$b;"
|
||||
a + b
|
||||
}
|
||||
assertEquals(6, a.data[0])
|
||||
assertEquals("1;2;3;", global)
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user