Skip to content

Commit e2092a4

Browse files
authored
Get rid of deprecated toChar() in JS-specific code (#2252)
Apparently -Werror flag is not applied to JS sources in kotlin.js.compiler=both mode
1 parent 2b77da3 commit e2092a4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

formats/json/jsMain/src/kotlinx/serialization/json/internal/DynamicDecoders.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ private open class DynamicInput(
134134
override fun decodeTaggedChar(tag: String): Char {
135135
return when (val value = getByTag(tag)) {
136136
is String -> if (value.length == 1) value[0] else throw SerializationException("$value can't be represented as Char")
137-
is Number -> value.toChar()
137+
is Number -> {
138+
val num = value as? Double ?: throw SerializationException("$value is not a Number")
139+
val codePoint = toJavascriptLong(num)
140+
if (codePoint < 0 || codePoint > Char.MAX_VALUE.code) throw SerializationException("$value can't be represented as Char because it's not in bounds of Char.MIN_VALUE..Char.MAX_VALUE")
141+
codePoint.toInt().toChar()
142+
}
138143
else -> throw SerializationException("$value can't be represented as Char")
139144
}
140145
}

0 commit comments

Comments
 (0)