realm-kotlin icon indicating copy to clipboard operation
realm-kotlin copied to clipboard

[K2] IllegalStateException: Multiple plugins generated nested class with same name Companion for class

Open rorbech opened this issue 1 year ago • 2 comments

How frequently does the bug occur?

Always

Description

Compiling a Realm model object with with Kotlin's K2 support will fail if other plugins adds a companion object too.

This is due to different compiler plugins not being able to detect additions made by other plugins. Filed in this issues.

The current workaround is to define a custom empty companion object. This will enable the plugins to augment the classes without causing conflicts.

@Serializable
class Sample: RealmObject {
   ....

   companion object
}

Stacktrace & log output

IllegalStateException: Multiple plugins generated nested class with same name Companion for class /Sample:
public final companion object Companion : R|kotlin/Any| {
}

public final companion object Companion : R|kotlin/Any| {
}

Can you reproduce the bug?

Always

Reproduction Steps

Compile a project that has multiple compiler plugins that adds a companion object with K2 support. One example could be to make a RealmObject @Serialziable.

@Serializable
class Sample: RealmObject {
   ...
}

Version

1.12+ with K2 support

What Atlas App Services are you using?

Both Atlas Device Sync and Atlas App Services

Are you using encryption?

No

Platform OS and version(s)

All platforms

Build environment

Kotlin version: 1.9.0 with kotlin.experimental.tryK2=true

rorbech avatar Nov 10 '23 15:11 rorbech

Will this bug be addressed in the future or will it always be required to add an empty companion object as soon as we use other plugins like kotlinx.serialization ?

Ynnck123 avatar Jun 10 '24 06:06 Ynnck123

@Ynnck123 It has been reported to Jetbrains and their current target is 2.1.0, but don't know the timeline and is also not any guarantee.

rorbech avatar Jun 10 '24 11:06 rorbech