Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling ::class.serializer() not working for a local class (Kotlin/JS) #113

Closed
rjaros opened this issue Apr 22, 2018 · 2 comments
Closed
Labels

Comments

@rjaros
Copy link

rjaros commented Apr 22, 2018

For a local class MyData (declared within a block) you can't get a serializer instance by calling MyData::class.serializer(). But the expression MyData.serializer() works fine.
For a top level or nested classes both forms are working ok.
This error makes all inline functions with reified type parameters unusable for such classes (for instance JSON.stringify()).

Platform: Kotlin/JS 1.2.40
Kotlin serialization: 0.4.2

@sandwwraith
Copy link
Member

sandwwraith commented Apr 23, 2018

Root of this issue is quite interesting. Serialization plugin adds a companion object for each serializable class to access serializer functions and for internal machinery. But in Kotlin language, companion objects in local classes are prohibited. While JVM compiler works well with such synthetic declarations, JS compiler perform some optimisations and doesn't define Companion property on local KClass, while direct companion access (MyData.serializer()) still works.

I'll investigate further to see if it's possible to disable this optimisation for synthetic declarations.

@qwwdfsad
Copy link
Contributor

We've decided not to implement this during the transition between old JS compiler backend to new JS IR backend.
Now all inline reified functions are using typeOf API instead of KClass, so the problem should be gone for most of the usages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants