shedaniel / cloth-config

Client-Sided API for Minecraft 1.14
Other
194 stars 71 forks source link

AutoConfig's PartitioningSerializer is incompatible with Kotlin classes with companion objects #137

Open NightEule5 opened 2 years ago

NightEule5 commented 2 years ago

I'm trying to use AutoConfig for a mod written in Kotlin. I'm wrapping a custom kotlinx.serialization serializer with a PartitioningSerializer, but the mod fails to load due to the companion object the kotlinx compiler plugin generates. The PartitioningSerializer class sees the static "Companion" field as a module, with no way to mark it as excluded.

When I have something like this for my config classes:

@AutoConfig(name = "mod")
@Serializable
data class Config(
    @TransitiveObject
    @Category("sectionA")
    override val sectionA: SectionAConfig = SectionAConfig(),
    @TransitiveObject
    @Category("sectionB")
    override val sectionB: SectionBConfig  = SectionBConfig()
)

@Config(name = "sectionA")
@Serializable
data class SectionAConfig(
    var sectionATestField: Long = -1
)

@Config(name = "sectionB")
@Serializable
data class SectionBConfig(
    var sectionBTestField: Boolean = true
)

I get a RuntimeException with the message: Invalid module: public static final mod.package.Config$Companion mod.package.Config.Companion. If this was Java, I could annotate this field with @ConfigEntry.Gui.Excluded, but this can only apply to a field, which I don't have access to from Kotlin. I either cannot use Kotlin's serialization plugin, or cannot use AutoConfig's PartitioningSerializer and instead must make my own.

I'm not sure why static fields would be included by default. Is this behavior intended?

I've attached a full crash log. The class names are slightly different from above, CoreConfig is the root config that has this issue.

crash-2021-12-17_20.11.47-client.txt