IR: return original KotlinType from IrTupe.toKotlinType() when it possible instead of creating new one

(cherry picked from commit e3b921a)
This commit is contained in:
Zalim Bashorov
2018-06-24 01:41:39 +03:00
committed by Dmitry Petrov
parent 1c2ac364c7
commit fa51b962b8
@@ -55,18 +55,24 @@ fun IrType.makeNullable() =
else
this
fun IrType.toKotlinType(): KotlinType = when (this) {
is IrSimpleType -> {
val classifier = this.classifier.descriptor
val arguments = this.arguments.mapIndexed { index, it ->
when (it) {
is IrTypeProjection -> TypeProjectionImpl(it.variance, it.type.toKotlinType())
is IrStarProjection -> StarProjectionImpl((classifier as ClassDescriptor).declaredTypeParameters[index])
else -> error(it)
}
}
classifier.defaultType.replace(newArguments = arguments).makeNullableAsSpecified(this.hasQuestionMark)
fun IrType.toKotlinType(): KotlinType {
originalKotlinType?.let {
return it
}
return when (this) {
is IrSimpleType -> {
val classifier = classifier.descriptor
val arguments = arguments.mapIndexed { index, it ->
when (it) {
is IrTypeProjection -> TypeProjectionImpl(it.variance, it.type.toKotlinType())
is IrStarProjection -> StarProjectionImpl((classifier as ClassDescriptor).declaredTypeParameters[index])
else -> error(it)
}
}
classifier.defaultType.replace(newArguments = arguments).makeNullableAsSpecified(hasQuestionMark)
}
else -> TODO(toString())
}
else -> TODO(this.toString())
}