File names of @serializable classes cause error building multiplatform project.
See original GitHub issueTask ‘compileKotlinIos’ fails with :
e: java.util.NoSuchElementException: Sequence contains no element matching the predicate. at org.jetbrains.kotlinx.serialization.compiler.backend.ir.IrBuilderExtension$DefaultImpls.serializableSyntheticConstructor(GeneratorHelpers.kt:620) at org.jetbrains.kotlinx.serialization.compiler.backend.ir.SerializableIrGenerator.serializableSyntheticConstructor(SerializableIrGenerator.kt:30) at org.jetbrains.kotlinx.serialization.compiler.backend.ir.SerializableIrGenerator.generateSuperSerializableCall(SerializableIrGenerator.kt:130) ...
with serializable abstract and inherited classes, but only if the name of the file containing the abstract class comes after the inheriting class alphabetically.
To Reproduce
In file Cabstract.kt:
@Serializable abstract class Cabstract( var foo: String ) { }
in file Binherit.kt:
@Serializable class Binherit( var bar: String = "" ) : Cabstract("") { }
‘./gradlew clean build’ results in error. Renaming the file ‘Binherit.kt’ to ‘Dinherit.kt’ allows the build to complete with no issue.
Expected behavior
Build should run fine regardless of file names.
Environment
- Kotlin version: 1.3.31
- Library version: 0.11.0
- Kotlin platforms: Native
- Gradle version: 5.3.1
- IDE version Android studio 3.3
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:13 (6 by maintainers)
Top GitHub Comments
Ok, that’s fun. It is actually related to names; the problem is the order in which compiler process classes. If file’s name with a derived class lexicographically smaller than the file’s with a base class, it is processed first and does not see special constructor added by the compiler plugin to the base class. The workaround is to rename files (you don’t need to rename classes themselves) or put the whole hierarchy in one file.
Thanks!
On Wed, 5 Jun 2019 at 18:33, Leonid Startsev notifications@github.com wrote: