diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmBridgesConstruction.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmBridgesConstruction.kt index 5f2ce332dc6..f5a9cb9a0b2 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmBridgesConstruction.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmBridgesConstruction.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.backend.wasm.lower +import org.jetbrains.kotlin.backend.common.ir.isOverridableOrOverrides import org.jetbrains.kotlin.backend.wasm.ir2wasm.erasedUpperBound import org.jetbrains.kotlin.ir.IrBuiltIns import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext @@ -32,12 +33,19 @@ data class WasmSignature( val name: Name, val extensionReceiverType: IrType?, val valueParametersType: List, - val returnType: IrType + val returnType: IrType, + // Needed for bridges to final non-override methods + // that indirectly implement interfaces. For example: + // interface I { fun foo() } + // class C1 { fun foo() {} } + // class C2 : C1(), I + val isVirtual: Boolean, ) { override fun toString(): String { val er = extensionReceiverType?.let { "(er: ${it.render()}) " } ?: "" val parameters = valueParametersType.joinToString(", ") { it.render() } - return "[$er$name($parameters) -> ${returnType.render()}]" + val nonVirtual = if (!isVirtual) "(non-virtual) " else "" + return "[$nonVirtual$er$name($parameters) -> ${returnType.render()}]" } } @@ -46,7 +54,8 @@ fun IrSimpleFunction.wasmSignature(irBuiltIns: IrBuiltIns): WasmSignature = name, extensionReceiverParameter?.type?.eraseGenerics(irBuiltIns), valueParameters.map { it.type.eraseGenerics(irBuiltIns) }, - returnType.eraseGenerics(irBuiltIns) + returnType.eraseGenerics(irBuiltIns), + isOverridableOrOverrides ) private fun IrType.eraseGenerics(irBuiltIns: IrBuiltIns): IrType { diff --git a/compiler/testData/codegen/box/callableReference/function/local/enumExtendsTrait.kt b/compiler/testData/codegen/box/callableReference/function/local/enumExtendsTrait.kt index 30d87bd148f..5ae74283aee 100644 --- a/compiler/testData/codegen/box/callableReference/function/local/enumExtendsTrait.kt +++ b/compiler/testData/codegen/box/callableReference/function/local/enumExtendsTrait.kt @@ -1,6 +1,3 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: IMPLICIT_INTERFACE_METHOD_IMPL - interface Named { val name: String } diff --git a/compiler/testData/codegen/box/regressions/kt4142.kt b/compiler/testData/codegen/box/regressions/kt4142.kt index 6c61934c750..d7fe122fda7 100644 --- a/compiler/testData/codegen/box/regressions/kt4142.kt +++ b/compiler/testData/codegen/box/regressions/kt4142.kt @@ -1,6 +1,3 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: IMPLICIT_INTERFACE_METHOD_IMPL - open class B { val name: String get() = "OK" diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index 3fd66b741ec..d11c5b99a81 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -1960,6 +1960,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/callableReference/function/local/constructorWithInitializer.kt"); } + @TestMetadata("enumExtendsTrait.kt") + public void testEnumExtendsTrait() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/function/local/enumExtendsTrait.kt"); + } + @TestMetadata("extension.kt") public void testExtension() throws Exception { runTest("compiler/testData/codegen/box/callableReference/function/local/extension.kt"); @@ -14981,6 +14986,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/regressions/kt39088.kt"); } + @TestMetadata("kt4142.kt") + public void testKt4142() throws Exception { + runTest("compiler/testData/codegen/box/regressions/kt4142.kt"); + } + @TestMetadata("kt4281.kt") public void testKt4281() throws Exception { runTest("compiler/testData/codegen/box/regressions/kt4281.kt");