[JS IR BE] Use Char boxing rules of current backend
This commit is contained in:
+8
-3
@@ -13,9 +13,7 @@ import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.realOverrideTarget
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.isNothing
|
||||
import org.jetbrains.kotlin.ir.types.makeNotNull
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
|
||||
|
||||
@@ -73,6 +71,13 @@ class AutoboxingTransformer(val context: JsIrBackendContext) : AbstractValueUsag
|
||||
val actualInlinedClass = actualType.getInlinedClass()
|
||||
val expectedInlinedClass = expectedType.getInlinedClass()
|
||||
|
||||
// Mimicking behaviour of current JS backend
|
||||
// TODO: Revisit
|
||||
if (
|
||||
(actualType is IrDynamicType && expectedType.makeNotNull().isChar()) ||
|
||||
(actualType.makeNotNull().isChar() && expectedType is IrDynamicType)
|
||||
) return this
|
||||
|
||||
val function = when {
|
||||
actualInlinedClass == null && expectedInlinedClass == null -> return this
|
||||
actualInlinedClass != null && expectedInlinedClass == null -> context.intrinsics.jsBoxIntrinsic
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package testUtils
|
||||
|
||||
fun isLegacyBackend(): Boolean =
|
||||
// Using eval to prevent DCE from thinking that following code depends on Kotlin module.
|
||||
eval("(typeof Kotlin != \"undefined\" && typeof Kotlin.kotlin != \"undefined\")").unsafeCast<Boolean>()
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// SKIP_MINIFICATION
|
||||
@JsName("foo")
|
||||
fun foo(): Char = '1'
|
||||
|
||||
val p1: Char = '2'
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1293
|
||||
open class A {
|
||||
fun foo(): Char = 'X'
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1283
|
||||
// EXPECTED_REACHABLE_NODES: 1276
|
||||
class A(val x: Char)
|
||||
|
||||
fun typeOf(x: dynamic): String = js("typeof x")
|
||||
|
||||
val expectedCharRepresentationInProperty = if (testUtils.isLegacyBackend()) "object" else "number"
|
||||
|
||||
fun box(): String {
|
||||
val a = A('0')
|
||||
|
||||
var r = typeOf(a.asDynamic().x)
|
||||
if (r != "object") return "fail1: $r"
|
||||
if (r != expectedCharRepresentationInProperty) return "fail1: $r"
|
||||
|
||||
r = typeOf(a.x)
|
||||
if (r != "number") return "fail2: $r"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1295
|
||||
// EXPECTED_REACHABLE_NODES: 1288
|
||||
interface I {
|
||||
val a: Char
|
||||
}
|
||||
@@ -18,9 +17,11 @@ object Y : I {
|
||||
}
|
||||
}
|
||||
|
||||
val expectedCharRepresentationInProperty = if (testUtils.isLegacyBackend()) "object" else "number"
|
||||
|
||||
fun box(): String {
|
||||
val t = jsTypeOf(X.asDynamic().a)
|
||||
if (t != "object") return "fail1: $t"
|
||||
if (t != expectedCharRepresentationInProperty) return "fail1: $t"
|
||||
|
||||
Y.a = '@'
|
||||
Y.a
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1292
|
||||
abstract class A<out T> {
|
||||
abstract fun foo(): T
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1282
|
||||
fun box(): String {
|
||||
val a = 'Q'.foo()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1283
|
||||
// CHECK_NOT_CALLED_IN_SCOPE: function=toBoxedChar scope=box$lambda
|
||||
// CHECK_CALLED_IN_SCOPE: function=unboxChar scope=box$lambda
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1296
|
||||
// EXPECTED_REACHABLE_NODES: 1289
|
||||
open class A {
|
||||
val foo: Char
|
||||
get() = 'X'
|
||||
@@ -35,6 +34,8 @@ fun typeOf(x: dynamic): String = js("typeof x")
|
||||
|
||||
var typeOfMutable = ""
|
||||
|
||||
val expectedCharRepresentationInProperty = if (testUtils.isLegacyBackend()) "object" else "number"
|
||||
|
||||
fun box(): String {
|
||||
val a = B()
|
||||
val b: I = B()
|
||||
@@ -46,23 +47,23 @@ fun box(): String {
|
||||
if (r2 != "object") return "fail2: $r2"
|
||||
|
||||
val r3 = typeOf(a.asDynamic().foo)
|
||||
if (r3 != "object") return "fail3: $r3"
|
||||
if (r3 != expectedCharRepresentationInProperty) return "fail3: $r3"
|
||||
|
||||
val r4 = typeOf(a.asDynamic().bar)
|
||||
if (r4 != "object") return "fail4: $r4"
|
||||
if (r4 != expectedCharRepresentationInProperty) return "fail4: $r4"
|
||||
|
||||
val r5 = typeOf(a.asDynamic().baz)
|
||||
if (r5 != "object") return "fail5: $r5"
|
||||
if (r5 != expectedCharRepresentationInProperty) return "fail5: $r5"
|
||||
|
||||
a.bar++
|
||||
val r6 = typeOf(a.asDynamic().bar)
|
||||
if (r6 != "object") return "fail6: $r6"
|
||||
if (r6 != expectedCharRepresentationInProperty) return "fail6: $r6"
|
||||
|
||||
val r7 = typeOf(a.asDynamic().mutable)
|
||||
if (r7 != "object") return "fail7: $r7"
|
||||
if (r7 != expectedCharRepresentationInProperty) return "fail7: $r7"
|
||||
|
||||
a.mutable = 'E'
|
||||
if (typeOfMutable != "number;object;number") return "fail8: $typeOfMutable"
|
||||
if (typeOfMutable != "number;$expectedCharRepresentationInProperty;number") return "fail8: $typeOfMutable"
|
||||
|
||||
val r9 = typeOf(a.mutable)
|
||||
if (r9 != "number") return "fail9: $r9"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1283
|
||||
fun foo(x: Any): String {
|
||||
return when (x) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1281
|
||||
fun box(): String {
|
||||
val a = CharArray(1)
|
||||
|
||||
Reference in New Issue
Block a user