I upgraded to kotlin 1.5.31 in the last few days a...
# kotlin-native
s
I upgraded to kotlin 1.5.31 in the last few days and I'm getting this error when compiling in iOS:
Copy code
@SharedImmutable is applicable only to top level declarations
and also this one in enums:
Copy code
@SharedImmutable is applicable only to val with backing field or to property with delegation
Example of data class:
Copy code
data class SomeDataClass(
    @SharedImmutable val someInt: Int,
    @SharedImmutable val someString: String,
    @SharedImmutable val someBool: Boolean
)
Example of enum class:
Copy code
enum class SomeEnumClass(
    /** The [Int] representation of this enum value. */
    @SharedImmutable val value: Int
) {
    @SharedImmutable ValueA(0),
    @SharedImmutable ValueB(1);

    companion object {
        internal fun fromInt(value: Int) = values().firstOrNull() { it.value == value } ?: ValueA
    }
}
For the record, I upgraded from 1.3.71 to 1.5.31 and I didn't have these issues before. The only other thing that I changed since the kotlin upgrade was to remove a 3rd-party lib @Throws annotation (multiplatform) and replace it with the one now available (since kotlin 1.4) in kotlin-stdlib-common.
What would be a "standard" way to work around this compilation error? Is calling
freeze()
instead of putting
@SharedImmutable
an option?
Nobody ever had this problem?