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")
}