Fix variance issues

This commit is contained in:
Artem Daugel-Dauge
2018-11-04 17:11:22 +03:00
parent fc4b92710e
commit e0be5f5a54
3 changed files with 6 additions and 12 deletions

View File

@@ -99,7 +99,7 @@ abstract class TypeRenderer {
else -> throw IllegalArgumentException(
"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)

View File

@@ -108,15 +108,7 @@ internal fun Type.asTypeName(
nullableProjection?.let { projection ->
when (projection) {
Type.Argument.Projection.IN -> WildcardTypeName.supertypeOf(argumentTypeName)
Type.Argument.Projection.OUT -> {
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.OUT -> WildcardTypeName.subtypeOf(argumentTypeName)
Type.Argument.Projection.STAR -> WildcardTypeName.STAR
Type.Argument.Projection.INV -> TODO("INV projection is unsupported")
}

View File

@@ -1143,11 +1143,13 @@ data class SmokeTestType(
val hasChildren: Boolean = false,
val favoriteFood: String? = null,
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 any: List<*>,
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 favoriteArrayValues: Array<String>,
val favoriteNullableArrayValues: Array<String?>,