Implement KTypeProjection.toString

The implementation is checked by tests on typeOf.

 #KT-30071 Fixed
This commit is contained in:
Alexander Udalov
2020-01-21 11:58:59 +01:00
parent 3a90e2dd75
commit e34a207725
2 changed files with 9 additions and 3 deletions
@@ -8,7 +8,6 @@ package kotlin.jvm.internal
import kotlin.reflect.*
@SinceKotlin("1.4")
@Suppress("NEWER_VERSION_IN_SINCE_KOTLIN", "API_NOT_AVAILABLE" /* See KT-30129 */) // TODO: remove this in 1.4
public class TypeReference(
override val classifier: KClassifier,
override val arguments: List<KTypeProjection>,
@@ -55,8 +54,8 @@ public class TypeReference(
else -> "kotlin.Array"
}
// TODO: this should be the implementation of KTypeProjection.toString, see KT-30071
@Suppress("NO_REFLECTION_IN_CLASS_PATH")
// This is based on KTypeProjection.toString, but uses [asString] to avoid adding the
// "reflection not supported" suffix to each type argument.
private fun KTypeProjection.asString(): String {
if (variance == null) return "*"
@@ -71,6 +71,13 @@ public data class KTypeProjection constructor(
*/
public val type: KType?
) {
override fun toString(): String = when (variance) {
null -> "*"
KVariance.INVARIANT -> type.toString()
KVariance.IN -> "in $type"
KVariance.OUT -> "out $type"
}
public companion object {
/**
* Star projection, denoted by the `*` character.