CORDA-2318 resolve type variables recursively (#4414)

* Resolve type variables recursively

* Clarify test

* Formatting
This commit is contained in:
Dominic Fox 2018-12-17 09:40:09 +00:00 committed by GitHub
parent 9d7be5cf21
commit c1d005ff21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -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
}

View File

@ -163,4 +163,26 @@ class RoundTripTests {
val deserialized = DeserializationInput(factory).deserialize(bytes)
assertEquals(mapOf("foo" to "bar"), deserialized.changedMembership.state.data.metadata)
}
interface I2<T> {
val t: T
}
data class C<A, B : A>(override val t: B) : I2<B>
@Test
fun recursiveTypeVariableResolution() {
val factory = testDefaultFactoryNoEvolution()
val instance = C<Collection<String>, List<String>>(emptyList())
val bytes = SerializationOutput(factory).serialize(instance)
DeserializationInput(factory).deserialize(bytes)
assertEquals(
"""
C (erased)(t: *): I2<*>
t: *
""".trimIndent(),
factory.getTypeInformation(instance::class.java).prettyPrint())
}
}