mirror of
https://github.com/fankes/moshi.git
synced 2025-10-20 00:19:21 +08:00
Merge pull request #733 from daugeldauge/fix-variance-issues
Fix variance issues in kotlin-codegen
This commit is contained in:
@@ -88,7 +88,7 @@ abstract class TypeRenderer {
|
|||||||
else -> throw IllegalArgumentException(
|
else -> throw IllegalArgumentException(
|
||||||
"Unrepresentable wildcard type. Cannot have more than one bound: $typeName")
|
"Unrepresentable wildcard type. Cannot have more than one bound: $typeName")
|
||||||
}
|
}
|
||||||
CodeBlock.of("%T.%L(%T::class.java)", Types::class, method, target)
|
CodeBlock.of("%T.%L(%T::class.java)", Types::class, method, target.asNonNull())
|
||||||
}
|
}
|
||||||
|
|
||||||
is TypeVariableName -> renderTypeVariable(typeName)
|
is TypeVariableName -> renderTypeVariable(typeName)
|
||||||
|
@@ -108,15 +108,7 @@ internal fun Type.asTypeName(
|
|||||||
nullableProjection?.let { projection ->
|
nullableProjection?.let { projection ->
|
||||||
when (projection) {
|
when (projection) {
|
||||||
Type.Argument.Projection.IN -> WildcardTypeName.supertypeOf(argumentTypeName)
|
Type.Argument.Projection.IN -> WildcardTypeName.supertypeOf(argumentTypeName)
|
||||||
Type.Argument.Projection.OUT -> {
|
Type.Argument.Projection.OUT -> WildcardTypeName.subtypeOf(argumentTypeName)
|
||||||
if (argumentTypeName == ANY) {
|
|
||||||
// This becomes a *, which we actually don't want here.
|
|
||||||
// List<Any> works with List<*>, but List<*> doesn't work with List<Any>
|
|
||||||
argumentTypeName
|
|
||||||
} else {
|
|
||||||
WildcardTypeName.subtypeOf(argumentTypeName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Type.Argument.Projection.STAR -> WildcardTypeName.STAR
|
Type.Argument.Projection.STAR -> WildcardTypeName.STAR
|
||||||
Type.Argument.Projection.INV -> TODO("INV projection is unsupported")
|
Type.Argument.Projection.INV -> TODO("INV projection is unsupported")
|
||||||
}
|
}
|
||||||
|
@@ -1157,11 +1157,13 @@ data class SmokeTestType(
|
|||||||
val hasChildren: Boolean = false,
|
val hasChildren: Boolean = false,
|
||||||
val favoriteFood: String? = null,
|
val favoriteFood: String? = null,
|
||||||
val favoriteDrink: String? = "Water",
|
val favoriteDrink: String? = "Water",
|
||||||
val wildcardOut: List<out String> = emptyList(),
|
val wildcardOut: MutableList<out String> = mutableListOf(),
|
||||||
|
val nullableWildcardOut: MutableList<out String?> = mutableListOf(),
|
||||||
val wildcardIn: Array<in String>,
|
val wildcardIn: Array<in String>,
|
||||||
val any: List<*>,
|
val any: List<*>,
|
||||||
val anyTwo: List<Any>,
|
val anyTwo: List<Any>,
|
||||||
val anyOut: List<out Any>,
|
// val anyOut: MutableList<out Any>, waiting for fix in kotlinpoet https://github.com/square/kotlinpoet/issues/520
|
||||||
|
val nullableAnyOut: MutableList<out Any?>,
|
||||||
val favoriteThreeNumbers: IntArray,
|
val favoriteThreeNumbers: IntArray,
|
||||||
val favoriteArrayValues: Array<String>,
|
val favoriteArrayValues: Array<String>,
|
||||||
val favoriteNullableArrayValues: Array<String?>,
|
val favoriteNullableArrayValues: Array<String?>,
|
||||||
|
Reference in New Issue
Block a user