[Wasm] Don't wrap single null expression into composite in WasmNullCoercingLowering

Otherwise, it breaks check/assert inside DeclarationGenerator::visitField (DeclarationGenerator.kt:458)

#KT-56166 In-Progress
This commit is contained in:
Zalim Bashorov
2023-01-27 00:08:40 +01:00
parent ca79711610
commit d1855371a0
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -7,9 +7,9 @@ package org.jetbrains.kotlin.backend.wasm.lower
import org.jetbrains.kotlin.backend.wasm.WasmBackendContext
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext
import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
import org.jetbrains.kotlin.ir.backend.js.lower.AbstractValueUsageLowering
import org.jetbrains.kotlin.ir.expressions.IrConst
import org.jetbrains.kotlin.ir.expressions.IrConstKind
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
@@ -27,10 +27,13 @@ import org.jetbrains.kotlin.ir.types.makeNotNull
class WasmNullCoercingLowering(private val contextx: WasmBackendContext) : AbstractValueUsageLowering(contextx) {
override fun IrExpression.useExpressionAsType(actualType: IrType, expectedType: IrType): IrExpression =
if (actualType.makeNotNull().isNothing() && actualType.isNullable() && !expectedType.makeNotNull().isNothing() && expectedType != contextx.wasmSymbols.voidType)
JsIrBuilder.buildComposite(
expectedType,
listOf(this, IrConstImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, expectedType, IrConstKind.Null, null))
)
if (this is IrConst<*> && this.kind == IrConstKind.Null)
IrConstImpl(this.startOffset, this.endOffset, expectedType, IrConstKind.Null, null)
else
JsIrBuilder.buildComposite(
expectedType,
listOf(this, IrConstImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, expectedType, IrConstKind.Null, null))
)
else
this
}