I've enabled collection literals as a test and not...
# compiler
e
I've enabled collection literals as a test and noticed the following:
Copy code
assertEquals(emptyList(), ["bbb"])
Translates to JS:
Copy code
assertEquals(emptyList(), listOf('bbb'));
While
Copy code
assertEquals([], ["bbb"])
Translates to JS:
Copy code
var tmp$ret$0 = emptyList();
assertEquals(tmp$ret$0, listOf('bbb'));
I guess this is because
[]
translates to
inline fun <T> listOf(): List<T> = _emptyList_()
Why not instead map
[]
directly to
emptyList()
?
Personal note on collection literals: I don't see myself going back to functions, the literal is way too handy.
🐕 4
g
Eventually, we'll introduce operators
of
for standard library classes:
Copy code
interface List<out T> {
    ...
    companion {
         inline operator fun <T> of(): List<T> = emptyList()
         ...
    }
}
and will resolve collection literals to them so the current behavior is the closest approximation we can get.
gratitude thank you 1