Support Nothing type in typeOf
The proper support will come in KT-15518, but that would be a breaking change even for stable Kotlin without kotlin-reflect. Before that issue is fixed, represent Nothing in types with the Void class, and use a flag in the no-reflect implementation to remember that it's not actually the Void class itself. #KT-39166 Fixed
This commit is contained in:
@@ -157,6 +157,11 @@ public class ReflectionFactoryImpl extends ReflectionFactory {
|
||||
return TypeOfImplKt.createMutableCollectionKType(type);
|
||||
}
|
||||
|
||||
// @Override // JPS
|
||||
public KType nothingType(KType type) {
|
||||
return TypeOfImplKt.createNothingType(type);
|
||||
}
|
||||
|
||||
// Misc
|
||||
|
||||
public static void clearCaches() {
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||
import org.jetbrains.kotlin.types.SimpleType
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
import kotlin.reflect.KType
|
||||
|
||||
internal fun createPlatformKType(lowerBound: KType, upperBound: KType): KType {
|
||||
@@ -39,3 +40,11 @@ private fun ClassDescriptor.readOnlyToMutable(): ClassDescriptor {
|
||||
?: throw IllegalArgumentException("Not a readonly collection: $this")
|
||||
return builtIns.getBuiltInClassByFqName(fqName)
|
||||
}
|
||||
|
||||
internal fun createNothingType(type: KType): KType {
|
||||
val kotlinType = (type as KTypeImpl).type
|
||||
require(kotlinType is SimpleType) { "Non-simple type cannot be a Nothing type: $type" }
|
||||
return KTypeImpl(
|
||||
KotlinTypeFactory.simpleType(kotlinType, constructor = kotlinType.builtIns.nothing.typeConstructor)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user