mirror of
https://github.com/corda/corda.git
synced 2025-05-29 21:54:26 +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 WildcardType -> this.upperBound
|
||||||
is ReconstitutedParameterizedType -> this
|
is ReconstitutedParameterizedType -> this
|
||||||
is ParameterizedType,
|
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
|
else -> this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,4 +163,26 @@ class RoundTripTests {
|
|||||||
val deserialized = DeserializationInput(factory).deserialize(bytes)
|
val deserialized = DeserializationInput(factory).deserialize(bytes)
|
||||||
assertEquals(mapOf("foo" to "bar"), deserialized.changedMembership.state.data.metadata)
|
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…
x
Reference in New Issue
Block a user