diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java index 7fdceab899f..b85b8d5eea4 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java @@ -3889,6 +3889,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { runTest("js/js.translator/testData/box/expression/typeCheck/complexIsInterface.kt"); } + @Test + @TestMetadata("kt55758.kt") + public void testKt55758() throws Exception { + runTest("js/js.translator/testData/box/expression/typeCheck/kt55758.kt"); + } + @Test @TestMetadata("simpleAsClass.kt") public void testSimpleAsClass() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java index 5249f9e4a26..f0bb07335b4 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java @@ -4505,6 +4505,12 @@ public class FirJsBoxTestGenerated extends AbstractFirJsBoxTest { runTest("js/js.translator/testData/box/expression/typeCheck/complexIsInterface.kt"); } + @Test + @TestMetadata("kt55758.kt") + public void testKt55758() throws Exception { + runTest("js/js.translator/testData/box/expression/typeCheck/kt55758.kt"); + } + @Test @TestMetadata("simpleAsClass.kt") public void testSimpleAsClass() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java index cbb521d6978..e3fa55218e7 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java @@ -4505,6 +4505,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/expression/typeCheck/complexIsInterface.kt"); } + @Test + @TestMetadata("kt55758.kt") + public void testKt55758() throws Exception { + runTest("js/js.translator/testData/box/expression/typeCheck/kt55758.kt"); + } + @Test @TestMetadata("simpleAsClass.kt") public void testSimpleAsClass() throws Exception { diff --git a/js/js.translator/testData/box/expression/typeCheck/kt55758.kt b/js/js.translator/testData/box/expression/typeCheck/kt55758.kt new file mode 100644 index 00000000000..8d65061d903 --- /dev/null +++ b/js/js.translator/testData/box/expression/typeCheck/kt55758.kt @@ -0,0 +1,19 @@ +// EXPECTED_REACHABLE_NODES: 1403 +// MODULE_KIND: COMMON_JS + +package foo + +@JsExport +interface Foo + +class Bar: Foo + +fun box(): String { + val foo : Foo = Bar() + + if(foo is Collection<*>) { + return "Fail: Foo is a Collection!" + } + + return "OK" +} \ No newline at end of file diff --git a/libraries/stdlib/js-ir/runtime/typeCheckUtils.kt b/libraries/stdlib/js-ir/runtime/typeCheckUtils.kt index 23dac3e982e..a7e1a2b6ee3 100644 --- a/libraries/stdlib/js-ir/runtime/typeCheckUtils.kt +++ b/libraries/stdlib/js-ir/runtime/typeCheckUtils.kt @@ -31,8 +31,20 @@ internal fun setMetadataFor( } } +// There was a problem with per-module compilation (KT-55758) when the top-level state (iid) was reinitialized during stdlib module initialization +// As a result we miss already incremented iid and had the same iids in two different modules +// So, to keep the state consistent it was moved into the object +private object InterfaceIdService { + var iid: Int = 0 +} + +private fun InterfaceIdService.generateInterfaceId(): Int { + iid += 1 + return iid +} + internal fun interfaceMeta(name: String?, associatedObjectKey: Number?, associatedObjects: dynamic, suspendArity: Array?): Metadata { - return createMetadata("interface", name, associatedObjectKey, associatedObjects, suspendArity, generateInterfaceId()) + return createMetadata("interface", name, associatedObjectKey, associatedObjects, suspendArity, InterfaceIdService.generateInterfaceId()) } internal fun objectMeta(name: String?, associatedObjectKey: Number?, associatedObjects: dynamic, suspendArity: Array?): Metadata { @@ -85,19 +97,6 @@ internal external interface Ctor { val prototype: dynamic } -private var iid: Int? = null - -@Suppress("SMARTCAST_IMPOSSIBLE") -internal fun generateInterfaceId(): Int { - if (iid == null) { - iid = 1 - } else { - iid += 1 - } - - return iid -} - @Suppress("UNUSED_PARAMETER") private fun getPrototypeOf(obj: dynamic) = js("Object.getPrototypeOf(obj)")