Skip to content

Commit

Permalink
Get rid of deprecated toChar() in JS-specific code (Kotlin#2252)
Browse files Browse the repository at this point in the history
Apparently -Werror flag is not applied to JS sources in kotlin.js.compiler=both mode
  • Loading branch information
sandwwraith committed Mar 29, 2023
1 parent 2b77da3 commit e2092a4
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ private open class DynamicInput(
override fun decodeTaggedChar(tag: String): Char {
return when (val value = getByTag(tag)) {
is String -> if (value.length == 1) value[0] else throw SerializationException("$value can't be represented as Char")
is Number -> value.toChar()
is Number -> {
val num = value as? Double ?: throw SerializationException("$value is not a Number")
val codePoint = toJavascriptLong(num)
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")
codePoint.toInt().toChar()
}
else -> throw SerializationException("$value can't be represented as Char")
}
}
Expand Down

0 comments on commit e2092a4

Please sign in to comment.