Skip to content

Mismatch between nullable and optional parameterΒ #378

@a8t3r

Description

@a8t3r

Describe the bug
I tried to use the binary serialization format for the client instead of json and found a bug - mismatch between nullability and optionality of function parameter.

This is how the optionality of the parameter is described in kotlinx.rpc.krpc.internal.CallableParametersSerializer:116:

isOptional = param.type.kType.isMarkedNullable

However optionality has different semantics, see kotlinx.serialization.descriptors.SerialDescriptor:398:

Example of optionality:
 * @Serializable
 * class Holder(
 *     val a: Int, // isElementOptional(0) == false
 *     val b: Int?, // isElementOptional(1) == false
 *     val c: Int? = null, // isElementOptional(2) == true
 *     val d: List<Int>, // isElementOptional(3) == false
 *     val e: List<Int> = listOf(1), // isElementOptional(4) == true
 * )

This is probably not a problem for json, because it has the explicitNulls setting, which is missing for protobuf.

To Reproduce
Enable protobuf serialization and try to invoke function like suspend fun test(a: String?) with null parameter value.

Expected behavior
The isOptional should be defined like isOptional = (param.foobar as kotlin.reflect.KParameter).isOptional

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions