[JS IR] Don't mark Char as a value class

Char will still be treated as a value class
(see JsInlineClassesUtils.kt)
This commit is contained in:
Sergej Jaskiewicz
2021-12-09 15:16:03 +03:00
committed by Space
parent f99b80c8d2
commit 6dc69adcc9
4 changed files with 22 additions and 9 deletions
+5 -3
View File
@@ -1,14 +1,16 @@
// EXPECTED_REACHABLE_NODES: 1372 // EXPECTED_REACHABLE_NODES: 1372
package foo package foo
class A
fun box(): String { fun box(): String {
assertEquals(true, 'A' == 'A') assertEquals(true, 'A' == 'A')
assertEquals(false, 'A'== 'B') assertEquals(false, 'A' == 'B')
assertEquals(false, ('A' as Any) == (65 as Any)) assertEquals(false, ('A' as Any) == (65 as Any))
// FIXME(KT-50157): assertEquals(true, 'A' === 'A')
assertEquals(false, 'A' === 'B')
assertEquals(false, ('A' as Any) === (65 as Any))
assertTrue(bar('Q')) assertTrue(bar('Q'))
assertFalse(bar('W')) assertFalse(bar('W'))
+2 -2
View File
@@ -1064,7 +1064,7 @@ public final class ByteArray {
public final operator fun set(index: kotlin.Int, value: kotlin.Byte): kotlin.Unit public final operator fun set(index: kotlin.Int, value: kotlin.Byte): kotlin.Unit
} }
/*∆*/ public final class Char : kotlin.Comparable<kotlin.Char> { public final class Char : kotlin.Comparable<kotlin.Char> {
public open override operator fun compareTo(other: kotlin.Char): kotlin.Int public open override operator fun compareTo(other: kotlin.Char): kotlin.Int
public final operator fun dec(): kotlin.Char public final operator fun dec(): kotlin.Char
@@ -3231,4 +3231,4 @@ public final annotation class UseExperimental : kotlin.Annotation {
public constructor UseExperimental(vararg markerClass: kotlin.reflect.KClass<out kotlin.Annotation>) public constructor UseExperimental(vararg markerClass: kotlin.reflect.KClass<out kotlin.Annotation>)
public final val markerClass: kotlin.Array<out kotlin.reflect.KClass<out kotlin.Annotation>> { get; } public final val markerClass: kotlin.Array<out kotlin.reflect.KClass<out kotlin.Annotation>> { get; }
} }
+2 -2
View File
@@ -1032,7 +1032,7 @@ public final class ByteArray {
public final operator fun set(index: kotlin.Int, value: kotlin.Byte): kotlin.Unit public final operator fun set(index: kotlin.Int, value: kotlin.Byte): kotlin.Unit
} }
/*∆*/ public final inline class Char : kotlin.Comparable<kotlin.Char> { public final class Char : kotlin.Comparable<kotlin.Char> {
/*∆*/ @kotlin.SinceKotlin(version = "1.5") /*∆*/ @kotlin.SinceKotlin(version = "1.5")
/*∆*/ @kotlin.WasExperimental(markerClass = {kotlin.ExperimentalStdlibApi::class}) /*∆*/ @kotlin.WasExperimental(markerClass = {kotlin.ExperimentalStdlibApi::class})
/*∆*/ public constructor Char(code: kotlin.UShort) /*∆*/ public constructor Char(code: kotlin.UShort)
@@ -3231,4 +3231,4 @@ public final annotation class UseExperimental : kotlin.Annotation {
public constructor UseExperimental(vararg markerClass: kotlin.reflect.KClass<out kotlin.Annotation>) public constructor UseExperimental(vararg markerClass: kotlin.reflect.KClass<out kotlin.Annotation>)
public final val markerClass: kotlin.Array<out kotlin.reflect.KClass<out kotlin.Annotation>> { get; } public final val markerClass: kotlin.Array<out kotlin.reflect.KClass<out kotlin.Annotation>> { get; }
} }
+13 -2
View File
@@ -5,11 +5,15 @@
package kotlin package kotlin
// Char is a magic class.
// Char is defined as a regular class, but we lower it as a value class.
// See [org.jetbrains.kotlin.ir.backend.js.utils.JsInlineClassesUtils.isClassInlineLike] for explanation.
/** /**
* Represents a 16-bit Unicode character. * Represents a 16-bit Unicode character.
* On the JVM, non-nullable values of this type are represented as values of the primitive type `char`. * On the JVM, non-nullable values of this type are represented as values of the primitive type `char`.
*/ */
public value class Char public /*value*/ class Char
@kotlin.internal.LowPriorityInOverloadResolution @kotlin.internal.LowPriorityInOverloadResolution
internal constructor(private val value: Int) : Comparable<Char> { internal constructor(private val value: Int) : Comparable<Char> {
@@ -76,6 +80,13 @@ internal constructor(private val value: Int) : Comparable<Char> {
@DeprecatedSinceKotlin(warningSince = "1.5") @DeprecatedSinceKotlin(warningSince = "1.5")
public fun toDouble(): Double = value.toDouble() public fun toDouble(): Double = value.toDouble()
override fun equals(other: Any?): Boolean {
if (other !is Char) return false
return this.value == other.value
}
override fun hashCode(): Int = value
// TODO implicit usages of toString and valueOf must be covered in DCE // TODO implicit usages of toString and valueOf must be covered in DCE
@Suppress("JS_NAME_PROHIBITED_FOR_OVERRIDE") @Suppress("JS_NAME_PROHIBITED_FOR_OVERRIDE")
@JsName("toString") @JsName("toString")
@@ -139,4 +150,4 @@ internal constructor(private val value: Int) : Comparable<Char> {
public const val SIZE_BITS: Int = 16 public const val SIZE_BITS: Int = 16
} }
} }