operator fun <T, U> T.invoke(x: U) = ":)"
# random
s
operator fun <T, U> T.invoke(x: U) = ":)"
😱 1
🧌 4
r
operator fun <T, U> T.invoke(u: U) = error(":)")
would make it assignable anywhere as it's
Nothing
(though it does show a warning of unreachable code)
u
makes total sense - but does not work in JS 😉
Copy code
operator fun <T, U> T.invoke(x: U) = ":)"

fun main(args: Array<String>) {
    val a = String { 1 }
    println(a)
}
r
Does
String
not have a companion object in JS? Your code only works on the JVM because
val a = String
is the same as
val a = String.Companion
.
u
Nope. That's not the problem. I get an unhandled JS Exception.
If I declare `class Blank{}`and use that instead of String, I get a 'real' error message like missing companion object.
r
That sounds like a bug. You should file it youtrack
u
But you did a good job of decoding `String { 1 }`;-)
r
What if you put a companion on
Blank
?
u
then it works
i guess.
let me try
r
I wonder what is special about
String
String crashes, class with companion works
r
I did some tests myself. It looks like all primitives crash, but other classes with companions from the standard library seem to work fine, so it's something to do with how JS handles primitives (it also appears the "Unhandled JavaScript exception" cannot be caught)
u
I won't find the time to report. Fell free to report it if you want.
u
Great.thx