From c1d005ff213fa2c9c1d0e6a851579ca14e69c18d Mon Sep 17 00:00:00 2001 From: Dominic Fox <40790090+distributedleetravis@users.noreply.github.com> Date: Mon, 17 Dec 2018 09:40:09 +0000 Subject: [PATCH] CORDA-2318 resolve type variables recursively (#4414) * Resolve type variables recursively * Clarify test * Formatting --- .../internal/model/TypeIdentifier.kt | 5 ++++- .../internal/amqp/RoundTripTests.kt | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/serialization/src/main/kotlin/net/corda/serialization/internal/model/TypeIdentifier.kt b/serialization/src/main/kotlin/net/corda/serialization/internal/model/TypeIdentifier.kt index a1788bce69..c40c75a0ad 100644 --- a/serialization/src/main/kotlin/net/corda/serialization/internal/model/TypeIdentifier.kt +++ b/serialization/src/main/kotlin/net/corda/serialization/internal/model/TypeIdentifier.kt @@ -225,7 +225,10 @@ internal fun Type.resolveAgainst(context: Type): Type = when (this) { is WildcardType -> this.upperBound is ReconstitutedParameterizedType -> this is ParameterizedType, - is TypeVariable<*> -> TypeToken.of(context).resolveType(this).type.upperBound + is TypeVariable<*> -> { + val resolved = TypeToken.of(context).resolveType(this).type.upperBound + if (resolved !is TypeVariable<*> || resolved == this) resolved else resolved.resolveAgainst(context) + } else -> this } diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/RoundTripTests.kt b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/RoundTripTests.kt index 14d6de11d6..07e63e5783 100644 --- a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/RoundTripTests.kt +++ b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/RoundTripTests.kt @@ -163,4 +163,26 @@ class RoundTripTests { val deserialized = DeserializationInput(factory).deserialize(bytes) assertEquals(mapOf("foo" to "bar"), deserialized.changedMembership.state.data.metadata) } + + interface I2 { + val t: T + } + + data class C(override val t: B) : I2 + + @Test + fun recursiveTypeVariableResolution() { + val factory = testDefaultFactoryNoEvolution() + val instance = C, List>(emptyList()) + + val bytes = SerializationOutput(factory).serialize(instance) + DeserializationInput(factory).deserialize(bytes) + + assertEquals( + """ + C (erased)(t: *): I2<*> + t: * + """.trimIndent(), + factory.getTypeInformation(instance::class.java).prettyPrint()) + } }