ZacSweers / MoshiX

Extensions for Moshi including IR plugins, moshi-sealed, and more.
Apache License 2.0
518 stars 37 forks source link

Error: Moshi.Builder.addAdapter() declaration needs ExperimentalStdlibApi opt-in #392

Closed proninyaroslav closed 1 year ago

proninyaroslav commented 1 year ago

Moshi: 1.14.0 MoshiX: 0.21.0 Kotlin: 1.8.10 KSP: 1.8.10-1.0.9

Also seen on MoshiX 0.20.0. The rollback of the version to 0.19.0 helped.

Code:

@JsonClass(generateAdapter = true, generator = "sealed:type")
sealed interface PrefFavoritesSort {
    val direction: PrefSortDirection

    @TypeLabel("unknown")
    object Unknown : PrefFavoritesSort {
        override val direction: PrefSortDirection
            get() = PrefSortDirection.Unknown
    }

    @TypeLabel("date_added")
    @JsonClass(generateAdapter = true)
    data class DateAdded(
        override val direction: PrefSortDirection
    ) : PrefFavoritesSort
}

Generated code:

@Suppress("DEPRECATION", "unused", "ClassName", "REDUNDANT_PROJECTION", "RedundantExplicitType",
    "LocalVariableName", "RedundantVisibilityModifier")
public class PrefFavoritesSortJsonAdapter(
  moshi: Moshi,
) : JsonAdapter<PrefFavoritesSort>() {
  private val runtimeAdapter: JsonAdapter<PrefFavoritesSort>

  init {
    val moshi_ = moshi.newBuilder()
            .addAdapter<PrefFavoritesSort.Unknown>(ObjectJsonAdapter(PrefFavoritesSort.Unknown))
        .build()
...

Build log: PrefFavoritesSortJsonAdapter.kt:26:14 This declaration needs opt-in. Its usage must be marked with '@kotlin.ExperimentalStdlibApi' or '@OptIn(kotlin.ExperimentalStdlibApi::class)'

grandstaish commented 1 year ago

We're getting the above too in version 0.21. The OptIn annotation seems to be generated in the wrong place?

Screenshot 2023-03-07 at 15 51 51