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

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

Open
NightEule5 opened this issue Dec 20, 2021 · 0 comments · May be fixed by #199
Open
Labels
bug Something isn't working

Comments

@NightEule5
Copy link

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

@shedaniel shedaniel added the bug Something isn't working label Dec 20, 2021
MattSturgeon added a commit to MattSturgeon/cloth-config that referenced this issue Mar 17, 2023
Static fields aren't relevant to config, but are sometimes added by JVM languages such as Kotlin.

Fixes shedaniel#137
@MattSturgeon MattSturgeon linked a pull request Mar 17, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants