From b4ebc1dca497ce71f58f7f13a17aba884f748d9d Mon Sep 17 00:00:00 2001 From: Igor Yakovlev Date: Mon, 19 Sep 2022 19:58:03 +0200 Subject: [PATCH] [WASM] Add missing implicit casts --- .../wasm/lower/WasmTypeOperatorLowering.kt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmTypeOperatorLowering.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmTypeOperatorLowering.kt index 7ecece22efe..037581d1787 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmTypeOperatorLowering.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmTypeOperatorLowering.kt @@ -234,6 +234,12 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme } } + if (toType == symbols.voidType) { + return builder.irCall(symbols.consumeAnyIntoVoid).apply { + putValueArgument(0, value) + } + } + return builder.irCall(symbols.refCast, type = toType).apply { putTypeArgument(0, toType) putValueArgument(0, value) @@ -324,9 +330,14 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme } private fun generateIsExternalClass(argument: IrExpression, klass: IrClass): IrExpression { - val function = context.mapping.wasmJsInteropFunctionToWrapper[context.mapping.wasmExternalClassToInstanceCheck[klass]!!]!! - return builder.irCall(function).also { - it.putValueArgument(0, argument) + val instanceCheckFunction = context.mapping.wasmExternalClassToInstanceCheck[klass]!! + val wrappedInstanceCheckIfAny = context.mapping.wasmJsInteropFunctionToWrapper[instanceCheckFunction] ?: instanceCheckFunction + + return builder.irCall(wrappedInstanceCheckIfAny).also { + it.putValueArgument( + index = 0, + valueArgument = narrowType(argument.type, context.irBuiltIns.anyType, argument) //TODO("Why we need it?) + ) } } }