Does/will Kotlin/JS support inline classes?

The topic says it all. Any information on this?

What do you mean by support? Code with inline-classes works fine in JS.

The IR compiler actually does inline the inline classes, whereas the old compiler treats inline classes as normal ones. Is that what you are asking about?

AFAIK interop with JS for inline classes is not designed yet, but you may expect some progress on that in 1.4.

1 Like

It depends what you mean by “works fine”. They compile, but they don’t inline (not on stable), not for me.

Thank you, I will try the 1.4 EAP

Maybe I’m still doing something wrong.
Tried with 1.4 M1 in IDE and in playground.

inline class InlineClass(val value: Int)
fun main() { println(InlineClass(2).value) }

still generates JS

  function main() {
    println((new InlineClass(2)).value);

Am I missing something?

Inline classes often do not inline even in JVM. I am not sure that there is a significant win from inlining classes in JS. Boxing is handled by the VM anyway. You could probably save something on the code size though.

I think a debate on usefulness of inline classes would just repeat what has been said lots of times before.
Some like them, some don’t.

It is not about liking, it is about working. On JVM they are more often not inlined than they are. In current state they usage and benefits from it are significantly limited.

1 Like