Just wondering why the following Kotlin code ```pr...
# javascript
e
Just wondering why the following Kotlin code
Copy code
private fun replOrThrow(message: String): Char {
  val repl = this.replacement // = private var replacement: Char? = '\uFFFD'

  if (repl != null) {
    return repl
  }

  throw MessageCharacterCodingException(message)
}
is translated to:
Copy code
function replOrThrow_1($this, message) {
  var repl = $this.qe_1;
  var tmp = repl;
  if (!((tmp == null ? null : new Char(tmp)) == null)) {
    return repl;
  }
  throw MessageCharacterCodingException.xd(message);
}
Specifically the
new Char(tmp)
thing. It looks like the char is not being treated as a simple number in this case (making it non-nullable doesn't help).
a
It looks weird for me too. Could you please fill out an issue for it?
e
Will do, thanks!
b
This is because we treat
Char
as a value class. Values of such classes are always boxed when they are put into a nullable storage. This makes sense on other targets like JVM, Native and Wasm, but on JS we indeed could do better.
thank you color 1
e
Seems like the
Char
class is the only one for which you reserve a special treatment, at least by looking at the sources. At least (I hope) the scope is limited.
👌 1