mirror of
https://github.com/corda/corda.git
synced 2024-12-20 21:43:14 +00:00
CORDA-2318 resolve type variables recursively (#4414)
* Resolve type variables recursively * Clarify test * Formatting
This commit is contained in:
parent
9d7be5cf21
commit
c1d005ff21
@ -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
|
||||
}
|
||||
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user