Introduce an API to convert TypeConstructorMarker to TypeParameterMarker

This commit is contained in:
Jinseong Jeon
2021-10-19 11:04:54 -07:00
committed by teamcity
parent a367b91aa1
commit 2dc2a90755
5 changed files with 22 additions and 3 deletions
@@ -28,11 +28,19 @@ internal class KtFe10TypeSystemCommonBackendContextForTypeMapping(
override fun TypeConstructorMarker.isTypeParameter(): Boolean { override fun TypeConstructorMarker.isTypeParameter(): Boolean {
require(this is TypeConstructor) require(this is TypeConstructor)
return when (this) { return when (this) {
is NewTypeVariableConstructor -> true is NewTypeVariableConstructor -> originalTypeParameter != null
else -> declarationDescriptor is TypeParameterDescriptor else -> declarationDescriptor is TypeParameterDescriptor
} }
} }
override fun TypeConstructorMarker.asTypeParameter(): TypeParameterMarker {
require(this is TypeConstructor)
return when (this) {
is NewTypeVariableConstructor -> originalTypeParameter!!
else -> declarationDescriptor as TypeParameterDescriptor
}
}
override fun TypeConstructorMarker.defaultType(): KotlinTypeMarker { override fun TypeConstructorMarker.defaultType(): KotlinTypeMarker {
require(this is TypeConstructor) require(this is TypeConstructor)
val declaration = declarationDescriptor ?: return ErrorUtils.createErrorType("Unresolved declaration descriptor ($this)") val declaration = declarationDescriptor ?: return ErrorUtils.createErrorType("Unresolved declaration descriptor ($this)")
@@ -104,4 +112,4 @@ internal class KtFe10TypeSystemCommonBackendContextForTypeMapping(
override fun functionNTypeConstructor(n: Int): TypeConstructorMarker { override fun functionNTypeConstructor(n: Int): TypeConstructorMarker {
return builtIns.getKFunction(n).typeConstructor return builtIns.getKFunction(n).typeConstructor
} }
} }
@@ -122,7 +122,7 @@ object AbstractTypeMapper {
} }
typeConstructor.isTypeParameter() -> { typeConstructor.isTypeParameter() -> {
val typeParameter = typeConstructor as TypeParameterMarker val typeParameter = typeConstructor.asTypeParameter()
return mapType(context, typeParameter.representativeUpperBound(), mode, null).also { asmType -> return mapType(context, typeParameter.representativeUpperBound(), mode, null).also { asmType ->
sw?.writeTypeVariable(typeParameter.getName(), asmType) sw?.writeTypeVariable(typeParameter.getName(), asmType)
} }
@@ -207,6 +207,11 @@ class ConeTypeSystemCommonBackendContextForTypeMapping(
return this is ConeTypeParameterLookupTag return this is ConeTypeParameterLookupTag
} }
override fun TypeConstructorMarker.asTypeParameter(): TypeParameterMarker {
require(isTypeParameter())
return this as ConeTypeParameterLookupTag
}
override fun TypeConstructorMarker.defaultType(): ConeSimpleKotlinType { override fun TypeConstructorMarker.defaultType(): ConeSimpleKotlinType {
require(this is ConeClassifierLookupTag) require(this is ConeClassifierLookupTag)
return when (this) { return when (this) {
@@ -223,6 +223,11 @@ private class IrTypeCheckerContextForTypeMapping(
return this is IrTypeParameterSymbol return this is IrTypeParameterSymbol
} }
override fun TypeConstructorMarker.asTypeParameter(): TypeParameterMarker {
require(isTypeParameter())
return this as IrTypeParameterSymbol
}
override fun TypeConstructorMarker.defaultType(): IrType { override fun TypeConstructorMarker.defaultType(): IrType {
return when (this) { return when (this) {
is IrClassSymbol -> owner.defaultType is IrClassSymbol -> owner.defaultType
@@ -53,6 +53,7 @@ interface TypeSystemCommonBackendContext : TypeSystemContext {
interface TypeSystemCommonBackendContextForTypeMapping : TypeSystemCommonBackendContext { interface TypeSystemCommonBackendContextForTypeMapping : TypeSystemCommonBackendContext {
fun TypeConstructorMarker.isTypeParameter(): Boolean fun TypeConstructorMarker.isTypeParameter(): Boolean
fun TypeConstructorMarker.asTypeParameter(): TypeParameterMarker
fun TypeConstructorMarker.defaultType(): KotlinTypeMarker fun TypeConstructorMarker.defaultType(): KotlinTypeMarker
fun TypeConstructorMarker.isScript(): Boolean fun TypeConstructorMarker.isScript(): Boolean