You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because of how the Kotlin compiler ends up building the output code for implementation by delegation, calling .serialize() on a proto class that implements an interface by delegation that also implements KtMessage ends up calling the wrong .serialize() method and produces an unexpected result.
interfaceMyInterface : KtMessage {
val value:String
}
funtest() {
val delegationProto =DelegationProto {
metadata =ImplementerProto {
value ="some value"
}
moreData ="some other value"
}
// Bug here: This is actually calling ImplementerProto's serialize() method, not DelegationProto's because// Kotlin's compiler overrides serialize() when doing the implementation by delegationval serializedProto = delegationProto.serialize()
// this throws an exceptionDelegationProto.deserialize(serializedProto)
// this succeedsImplementerProto.deserialize(serializedProto)
// doing this gets the correct value, because we're calling into serialize(KtSerializer),// which each generated proto class overrides explicitlyval s =ByteArray(serializedProto.messageSize).apply {
serializedProto.serialize(serializer(CodedOutputStream.newInstance(this)))
}
}
The text was updated successfully, but these errors were encountered:
Description
Because of how the Kotlin compiler ends up building the output code for implementation by delegation, calling
.serialize()
on a proto class that implements an interface by delegation that also implements KtMessage ends up calling the wrong.serialize()
method and produces an unexpected result.Reproduction steps
The text was updated successfully, but these errors were encountered: