[PSI2IR] Support DefinitelyNotNull type translation in Psi2Ir
This commit is contained in:
committed by
TeamCityServer
parent
101afded69
commit
29728efbf7
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.ir.types.IrType
|
|||||||
import org.jetbrains.kotlin.ir.types.IrTypeAbbreviation
|
import org.jetbrains.kotlin.ir.types.IrTypeAbbreviation
|
||||||
import org.jetbrains.kotlin.ir.types.IrTypeProjection
|
import org.jetbrains.kotlin.ir.types.IrTypeProjection
|
||||||
import org.jetbrains.kotlin.ir.types.impl.*
|
import org.jetbrains.kotlin.ir.types.impl.*
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections
|
import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections
|
||||||
import org.jetbrains.kotlin.types.typesApproximation.approximateCapturedTypes
|
import org.jetbrains.kotlin.types.typesApproximation.approximateCapturedTypes
|
||||||
@@ -45,6 +44,8 @@ abstract class TypeTranslator(
|
|||||||
|
|
||||||
private val erasureStack = Stack<PropertyDescriptor>()
|
private val erasureStack = Stack<PropertyDescriptor>()
|
||||||
|
|
||||||
|
private val supportDefinitelyNotNullTypes: Boolean = languageVersionSettings.supportsFeature(LanguageFeature.DefinitelyNonNullableTypes)
|
||||||
|
|
||||||
protected abstract fun isTypeAliasAccessibleHere(typeAliasDescriptor: TypeAliasDescriptor): Boolean
|
protected abstract fun isTypeAliasAccessibleHere(typeAliasDescriptor: TypeAliasDescriptor): Boolean
|
||||||
|
|
||||||
fun enterScope(irElement: IrTypeParametersContainer) {
|
fun enterScope(irElement: IrTypeParametersContainer) {
|
||||||
@@ -86,17 +87,20 @@ abstract class TypeTranslator(
|
|||||||
?: symbolTable.referenceTypeParameter(originalTypeParameter)
|
?: symbolTable.referenceTypeParameter(originalTypeParameter)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun translateType(kotlinType: KotlinType): IrType =
|
fun translateType(kotlinType: KotlinType): IrType {
|
||||||
translateType(kotlinType, Variance.INVARIANT).type
|
return translateType(kotlinType, Variance.INVARIANT).type
|
||||||
|
}
|
||||||
|
|
||||||
private fun translateType(kotlinType: KotlinType, variance: Variance): IrTypeProjection {
|
private fun translateType(kotlinType: KotlinType, variance: Variance): IrTypeProjection {
|
||||||
val approximatedType = approximate(kotlinType)
|
val approximatedType = approximate(kotlinType.unwrap())
|
||||||
|
|
||||||
when {
|
when {
|
||||||
approximatedType.isError ->
|
approximatedType.isError ->
|
||||||
return IrErrorTypeImpl(approximatedType, translateTypeAnnotations(approximatedType), variance)
|
return IrErrorTypeImpl(approximatedType, translateTypeAnnotations(approximatedType), variance)
|
||||||
approximatedType.isDynamic() ->
|
approximatedType.isDynamic() ->
|
||||||
return IrDynamicTypeImpl(approximatedType, translateTypeAnnotations(approximatedType), variance)
|
return IrDynamicTypeImpl(approximatedType, translateTypeAnnotations(approximatedType), variance)
|
||||||
|
supportDefinitelyNotNullTypes && approximatedType is DefinitelyNotNullType ->
|
||||||
|
return makeTypeProjection(IrDefinitelyNotNullTypeImpl(approximatedType, translateType(approximatedType.original)), variance)
|
||||||
}
|
}
|
||||||
|
|
||||||
val upperType = approximatedType.upperIfFlexible()
|
val upperType = approximatedType.upperIfFlexible()
|
||||||
|
|||||||
Reference in New Issue
Block a user