diff --git a/kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/TypeRenderer.kt b/kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/TypeRenderer.kt index f78b3b8..067f5e3 100644 --- a/kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/TypeRenderer.kt +++ b/kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/TypeRenderer.kt @@ -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) diff --git a/kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/metadata.kt b/kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/metadata.kt index 8b20a03..9053b2e 100644 --- a/kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/metadata.kt +++ b/kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/metadata.kt @@ -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 works with List<*>, but List<*> doesn't work with List - 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") } diff --git a/kotlin/tests/src/test/kotlin/com/squareup/moshi/kotlin/codgen/GeneratedAdaptersTest.kt b/kotlin/tests/src/test/kotlin/com/squareup/moshi/kotlin/codgen/GeneratedAdaptersTest.kt index 38c8d58..1d0f45d 100644 --- a/kotlin/tests/src/test/kotlin/com/squareup/moshi/kotlin/codgen/GeneratedAdaptersTest.kt +++ b/kotlin/tests/src/test/kotlin/com/squareup/moshi/kotlin/codgen/GeneratedAdaptersTest.kt @@ -1143,11 +1143,13 @@ data class SmokeTestType( val hasChildren: Boolean = false, val favoriteFood: String? = null, val favoriteDrink: String? = "Water", - val wildcardOut: List = emptyList(), + val wildcardOut: MutableList = mutableListOf(), + val nullableWildcardOut: MutableList = mutableListOf(), val wildcardIn: Array, val any: List<*>, val anyTwo: List, - val anyOut: List, +// val anyOut: MutableList, waiting for fix in kotlinpoet https://github.com/square/kotlinpoet/issues/520 + val nullableAnyOut: MutableList, val favoriteThreeNumbers: IntArray, val favoriteArrayValues: Array, val favoriteNullableArrayValues: Array,