[Wasm] Fix transforming setField in an inline class constructor body
IrSetField was transformed to its value to preserve side effects This transformation produced invalid IR in cases where IrSetField used in Unit-returning expression context. This commit fixes it by producing Unit-typed expression ^KT-59084 Fixed
This commit is contained in:
committed by
Space Team
parent
6fba6a2e3c
commit
833c8b2cd4
+10
-1
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.backend.common.BodyLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.DeclarationTransformer
|
||||
import org.jetbrains.kotlin.backend.common.getOrPut
|
||||
import org.jetbrains.kotlin.backend.common.ir.isPure
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
@@ -105,7 +106,15 @@ class InlineClassLowering(val context: CommonBackendContext) {
|
||||
}
|
||||
expression.transformChildrenVoid()
|
||||
if (isMemberFieldSet) {
|
||||
return expression.value
|
||||
return builder.irBlock {
|
||||
if (!expression.value.isPure(true)) {
|
||||
// Preserving side effects
|
||||
+expression.value
|
||||
// Adding empty block to provide Unit value.
|
||||
// This is useful when original IrSetField is the last statement in a Unit-returning block.
|
||||
+builder.irBlock {}
|
||||
}
|
||||
}
|
||||
}
|
||||
return expression
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// TARGET_BACKEND: WASM
|
||||
|
||||
inline class JsDynamic(val value: JsAny?)
|
||||
|
||||
val JsAny?.jsDyn: JsDynamic get() = JsDynamic(this)
|
||||
|
||||
fun test(): Boolean {
|
||||
val jsDynamic: JsAny? = 1.toJsNumber()
|
||||
val jsDyn = jsDynamic.jsDyn
|
||||
return jsDyn.value == jsDynamic
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (!test()) {
|
||||
return "Fail"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -121,6 +121,12 @@ public class FirWasmCodegenWasmJsInteropTestGenerated extends AbstractFirWasmCod
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/kt59082.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt59084.kt")
|
||||
public void testKt59084() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/kt59084.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaAdapterNameClash.kt")
|
||||
public void testLambdaAdapterNameClash() throws Exception {
|
||||
|
||||
+6
@@ -121,6 +121,12 @@ public class K1WasmCodegenWasmJsInteropTestGenerated extends AbstractK1WasmCodeg
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/kt59082.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt59084.kt")
|
||||
public void testKt59084() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/kt59084.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaAdapterNameClash.kt")
|
||||
public void testLambdaAdapterNameClash() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user