[K/JS] Move global interface id state into an object to prevent interface ids reinitialization ^Fixed KT-55758
This commit is contained in:
@@ -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 {
|
||||
|
||||
+6
@@ -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 {
|
||||
|
||||
+6
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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<Int>?): 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<Int>?): 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)")
|
||||
|
||||
Reference in New Issue
Block a user