cashapp / molecule

Build a StateFlow stream using Jetpack Compose
https://cashapp.github.io/molecule/docs/1.x/
Apache License 2.0
1.89k stars 81 forks source link

Integration issue with kotlinx.serialization plugin: kotlinx.serialization compiler plugin internal error: unable to transform declaration #178

Closed xxfast closed 1 year ago

xxfast commented 1 year ago

Molecule version: 0.7.0 Kotlin version: 1.8.0, 1.8.10 Kotlinx Serialisation: 1.5.0-RC

> Task :shared:compileKotlinIosSimulatorArm64 FAILED
e: Compilation failed: Back-end: Please report this problem https://kotl.in/issue
/Users/TFNX46/Developer/MULTIPLATFORM/KotlinXIssues/shared/src/commonMain/kotlin/io/github/xxfast/kotlinx/issues/Models.kt:5:1
Problem with `@Serializable
@StabilityInferred(parameters = 0)
sealed class EntitySearchResult {
  protected constructor() /* primary */ {
    super/*Any*/()
    /* <init>() */

  }

  companion object Companion : SerializerFactory {
    private constructor() /* primary */ {
      super/*Any*/()
      /* <init>() */

    }

    @GCUnsafeCall(callee = "Kotlin_Any_equals")
    external /* fake */ override operator fun equals(other: Any?): Boolean
    /* fake */ override fun hashCode(): Int
    /* fake */ override fun toString(): String
    fun serializer(): KSerializer<EntitySearchResult>
    override fun serializer(vararg typeParamsSerializers: KSerializer<*>): KSerializer<*>
  }

  @GCUnsafeCall(callee = "Kotlin_Any_equals")
  external /* fake */ override operator fun equals(other: Any?): Boolean
  /* fake */ override fun hashCode(): Int
  /* fake */ override fun toString(): String
  @Deprecated(message = "This synthesized declaration should not be used directly", replaceWith = ReplaceWith(expression = "", imports = []), level = DeprecationLevel.HIDDEN)
  constructor(seen1: Int, serializationConstructorMarker: SerializationConstructorMarker?) 
  private val $stableprop: Int
    field = 0

}

`
Details: kotlinx.serialization compiler plugin internal error: unable to transform declaration, see cause

 * Source files: Models.kt
 * Compiler version info: Konan: 1.8.10 / Kotlin: 1.8.10
 * Output kind: LIBRARY

This took me a while to figure out what exactly was causing this problem. I've raised this issue on kotlinx.serialization issue tracker but from what they mentioned, this was due to

In short, compose plugin produces incorrect IR which serialization plugin is unable to work with

I was originally suspecting it was compose-multiplatform that was causing this issue (given that there is a similar issue), but after isolating the issue to a standalone project - i was able to pinpoint this to molecule, or the version of compose compiler plugin that used by molecule gradle plugin, is what causing this issue.

Full stacktace.log Standalone project to reproduce the issue: KotlinXIssues.zip

JakeWharton commented 1 year ago

Pretty sure this is fixed by https://github.com/JetBrains/androidx/pull/371 and we just need to point at the JetBrains compiler and give up pointing at AndroidX. This is the approach we've taken with Redwood now. May as well do the same here.

xxfast commented 1 year ago

@JakeWharton why was this switched from jetbrains to androidx compose compiler?

JakeWharton commented 1 year ago

Because all the necessary fixes were upstreamed