Skip to content

Commit

Permalink
Make $serializer generic constructor public
Browse files Browse the repository at this point in the history
If a serializable class has generic type parameters, its serializer is not an object
and has a specialized constructor. This constructor was public in K1 and should
be public in K2 so it can be called from other serializable classes
(in case class is e.g., part of sealed hierarchy).

#KT-63402 Fixed
  • Loading branch information
sandwwraith authored and qodana-bot committed Nov 28, 2023
1 parent 51e3e9a commit 662bff7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class SerializationFirResolveExtension(session: FirSession) : FirDeclarationGene

if (owner.name == SerialEntityNames.SERIALIZER_CLASS_NAME && owner.typeParameterSymbols.isNotEmpty()) {
result += createConstructor(owner, SerializationPluginKey) {
visibility = Visibilities.Private
visibility = Visibilities.Public
owner.typeParameterSymbols.forEachIndexed { i, typeParam ->
valueParameter(
name = Name.identifier("${SerialEntityNames.typeArgPrefix}$i"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// TARGET_BACKEND: JVM_IR

// WITH_STDLIB

// FILE: a.kt

import kotlinx.serialization.*

@Serializable
sealed class Base {
abstract val id: Long
}

// FILE: b.kt

import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*

@Serializable
class DerivedOtherFile<Value>(
override val id: Long,
val value: Value
) : Base()

fun box(): String {
val desc = Base.serializer().descriptor.kind
return if (desc == PolymorphicKind.SEALED) "OK" else desc.toString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ public final class Box$$serializer : java/lang/Object, kotlinx/serialization/int

private void <init>()

private void <init>(kotlinx.serialization.KSerializer typeSerial0)

public void <init>(kotlinx.serialization.KSerializer typeSerial0, kotlin.jvm.internal.DefaultConstructorMarker $constructor_marker)
public void <init>(kotlinx.serialization.KSerializer typeSerial0)

public final kotlinx.serialization.KSerializer[] childSerializers()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ FILE: classWithGenericParameters.kt
super<R|kotlin/Any|>()
}

private constructor<T, V>(typeSerial0: R|kotlinx/serialization/KSerializer<T>|, typeSerial1: R|kotlinx/serialization/KSerializer<V>|): R|GenericBox.$serializer<T, V>|
public constructor<T, V>(typeSerial0: R|kotlinx/serialization/KSerializer<T>|, typeSerial1: R|kotlinx/serialization/KSerializer<V>|): R|GenericBox.$serializer<T, V>|

}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 662bff7

Please sign in to comment.