Support mutable collection types in typeOf

flexibleTypes_1_6.kt is fixed for JVM IR in a subsequent commit.

 #KT-35877 Fixed
This commit is contained in:
Alexander Udalov
2021-05-21 20:39:29 +02:00
parent 6e975b3498
commit 0cb905a4b1
19 changed files with 327 additions and 15 deletions
@@ -190,4 +190,9 @@ public class Reflection {
public static KType platformType(KType lowerBound, KType upperBound) {
return factory.platformType(lowerBound, upperBound);
}
@SinceKotlin(version = "1.6")
public static KType mutableCollectionType(KType type) {
return factory.mutableCollectionType(type);
}
}
@@ -96,6 +96,19 @@ public class ReflectionFactory {
@SinceKotlin(version = "1.6")
public KType platformType(KType lowerBound, KType upperBound) {
return new TypeReference(lowerBound.getClassifier(), lowerBound.getArguments(), lowerBound.isMarkedNullable(), upperBound);
return new TypeReference(
lowerBound.getClassifier(), lowerBound.getArguments(), lowerBound.isMarkedNullable(),
upperBound,
((TypeReference) lowerBound).getMutableCollectionType$kotlin_stdlib()
);
}
@SinceKotlin(version = "1.6")
public KType mutableCollectionType(KType type) {
return new TypeReference(
type.getClassifier(), type.getArguments(), type.isMarkedNullable(),
((TypeReference) type).getPlatformTypeUpperBound$kotlin_stdlib(),
true
);
}
}
@@ -14,13 +14,14 @@ public class TypeReference /* @SinceKotlin("1.6") constructor */(
override val classifier: KClassifier,
override val arguments: List<KTypeProjection>,
override val isMarkedNullable: Boolean,
private val platformTypeUpperBound: KType?,
internal val platformTypeUpperBound: KType?,
internal val mutableCollectionType: Boolean,
) : KType {
constructor(
classifier: KClassifier,
arguments: List<KTypeProjection>,
isMarkedNullable: Boolean,
) : this(classifier, arguments, isMarkedNullable, null)
) : this(classifier, arguments, isMarkedNullable, null, false)
override val annotations: List<Annotation>
get() = emptyList()
@@ -28,7 +29,7 @@ public class TypeReference /* @SinceKotlin("1.6") constructor */(
override fun equals(other: Any?): Boolean =
other is TypeReference &&
classifier == other.classifier && arguments == other.arguments && isMarkedNullable == other.isMarkedNullable &&
platformTypeUpperBound == other.platformTypeUpperBound
platformTypeUpperBound == other.platformTypeUpperBound && mutableCollectionType == other.mutableCollectionType
override fun hashCode(): Int =
(classifier.hashCode() * 31 + arguments.hashCode()) * 31 + isMarkedNullable.hashCode()