Support flexible types internally in typeOf

#KT-45066 Fixed
This commit is contained in:
Alexander Udalov
2021-05-21 19:27:59 +02:00
parent 26cdb2f928
commit 6e975b3498
21 changed files with 358 additions and 42 deletions
@@ -146,6 +146,11 @@ public class ReflectionFactoryImpl extends ReflectionFactory {
// Do nothing. KTypeParameterImpl implementation will load upper bounds from the metadata.
}
// @Override // JPS
public KType platformType(KType lowerBound, KType upperBound) {
return TypeOfImplKt.createPlatformKType(lowerBound, upperBound);
}
// Misc
public static void clearCaches() {
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.reflect.jvm.internal
import org.jetbrains.kotlin.types.KotlinTypeFactory
import org.jetbrains.kotlin.types.SimpleType
import kotlin.reflect.KType
internal fun createPlatformKType(lowerBound: KType, upperBound: KType): KType {
// lowerBound/upperBound are guaranteed to be KTypeImpl over SimpleType, as long as this function is only used from the bytecode
// generated by the compiler for `typeOf`.
return KTypeImpl(
KotlinTypeFactory.flexibleType(
(lowerBound as KTypeImpl).type as SimpleType,
(upperBound as KTypeImpl).type as SimpleType,
)
)
}