IR use abstract classes in IrType hierarchy
This commit is contained in:
@@ -8,10 +8,12 @@ package org.jetbrains.kotlin.ir.types
|
||||
import org.jetbrains.kotlin.ir.declarations.IrAnnotationContainer
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeAliasSymbol
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrTypeBase
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
|
||||
interface IrType : KotlinTypeMarker, IrAnnotationContainer {
|
||||
abstract class IrType : KotlinTypeMarker, IrAnnotationContainer {
|
||||
|
||||
/**
|
||||
* @return true if this type is equal to [other] symbolically. Note that this is NOT EQUIVALENT to the full type checking algorithm
|
||||
@@ -21,29 +23,28 @@ interface IrType : KotlinTypeMarker, IrAnnotationContainer {
|
||||
* Classes are compared by FQ names, which means that even if two types refer to different symbols of the class with the same FQ name,
|
||||
* such types will be considered equal. Type annotations do not have any effect on the behavior of this method.
|
||||
*/
|
||||
override fun equals(other: Any?): Boolean
|
||||
abstract override fun equals(other: Any?): Boolean
|
||||
|
||||
override fun hashCode(): Int
|
||||
abstract override fun hashCode(): Int
|
||||
}
|
||||
|
||||
interface IrErrorType : IrType
|
||||
abstract class IrErrorType(kotlinType: KotlinType?) : IrTypeBase(kotlinType)
|
||||
|
||||
interface IrDynamicType : IrType, DynamicTypeMarker
|
||||
abstract class IrDynamicType(kotlinType: KotlinType?) : IrTypeBase(kotlinType), DynamicTypeMarker
|
||||
|
||||
interface IrDefinitelyNotNullType : IrType, DefinitelyNotNullTypeMarker {
|
||||
val original: IrType
|
||||
abstract class IrDefinitelyNotNullType(kotlinType: KotlinType?) : IrTypeBase(kotlinType), DefinitelyNotNullTypeMarker {
|
||||
abstract val original: IrType
|
||||
}
|
||||
|
||||
interface IrSimpleType : IrType, SimpleTypeMarker, TypeArgumentListMarker {
|
||||
val classifier: IrClassifierSymbol
|
||||
val hasQuestionMark: Boolean
|
||||
val arguments: List<IrTypeArgument>
|
||||
val abbreviation: IrTypeAbbreviation?
|
||||
abstract class IrSimpleType(kotlinType: KotlinType?) : IrTypeBase(kotlinType), SimpleTypeMarker, TypeArgumentListMarker {
|
||||
abstract val classifier: IrClassifierSymbol
|
||||
abstract val hasQuestionMark: Boolean
|
||||
abstract val arguments: List<IrTypeArgument>
|
||||
abstract val abbreviation: IrTypeAbbreviation?
|
||||
}
|
||||
|
||||
interface IrTypeArgument : TypeArgumentMarker {
|
||||
override fun equals(other: Any?): Boolean
|
||||
|
||||
override fun hashCode(): Int
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.types.Variance
|
||||
class IrDefinitelyNotNullTypeImpl(
|
||||
kotlinType: KotlinType?,
|
||||
override val original: IrType,
|
||||
) : IrTypeBase(kotlinType), IrDefinitelyNotNullType {
|
||||
) : IrDefinitelyNotNullType(kotlinType) {
|
||||
|
||||
override val annotations: List<IrConstructorCall>
|
||||
get() = original.annotations
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
abstract class IrAbstractSimpleType(kotlinType: KotlinType?) : IrTypeBase(kotlinType), IrSimpleType {
|
||||
abstract class IrAbstractSimpleType(kotlinType: KotlinType?) : IrSimpleType(kotlinType) {
|
||||
|
||||
override val variance: Variance
|
||||
get() = Variance.INVARIANT
|
||||
|
||||
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.types.model.CapturedTypeConstructorMarker
|
||||
import org.jetbrains.kotlin.types.model.CapturedTypeMarker
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
abstract class IrTypeBase(val kotlinType: KotlinType?) : IrType, IrTypeProjection {
|
||||
abstract class IrTypeBase(val kotlinType: KotlinType?) : IrType(), IrTypeProjection {
|
||||
override val type: IrType get() = this
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class IrErrorTypeImpl(
|
||||
kotlinType: KotlinType?,
|
||||
override val annotations: List<IrConstructorCall>,
|
||||
override val variance: Variance,
|
||||
) : IrTypeBase(kotlinType), IrErrorType {
|
||||
) : IrErrorType(kotlinType) {
|
||||
override fun equals(other: Any?): Boolean = other is IrErrorTypeImpl
|
||||
|
||||
override fun hashCode(): Int = IrErrorTypeImpl::class.java.hashCode()
|
||||
@@ -35,7 +35,7 @@ class IrDynamicTypeImpl(
|
||||
kotlinType: KotlinType?,
|
||||
override val annotations: List<IrConstructorCall>,
|
||||
override val variance: Variance,
|
||||
) : IrTypeBase(kotlinType), IrDynamicType {
|
||||
) : IrDynamicType(kotlinType) {
|
||||
override fun equals(other: Any?): Boolean = other is IrDynamicTypeImpl
|
||||
|
||||
override fun hashCode(): Int = IrDynamicTypeImpl::class.java.hashCode()
|
||||
@@ -62,7 +62,7 @@ object IrStarProjectionImpl : IrStarProjection {
|
||||
* however this could lead to a situation where we forget to set return type sometimes. This would result in crashes at unexpected moments,
|
||||
* especially in Kotlin/JS where function return types are not present in the resulting binary files.
|
||||
*/
|
||||
object IrUninitializedType : IrType {
|
||||
object IrUninitializedType : IrType() {
|
||||
override val annotations: List<IrConstructorCall> = emptyList()
|
||||
|
||||
override fun equals(other: Any?): Boolean = this === other
|
||||
@@ -81,7 +81,10 @@ class IrCapturedType(
|
||||
val lowerType: IrType?,
|
||||
projection: IrTypeArgument,
|
||||
typeParameter: IrTypeParameter
|
||||
) : IrSimpleType, CapturedTypeMarker {
|
||||
) : IrSimpleType(null), CapturedTypeMarker {
|
||||
|
||||
override val variance: Variance
|
||||
get() = TODO("Not yet implemented")
|
||||
|
||||
class Constructor(val argument: IrTypeArgument, val typeParameter: IrTypeParameter) :
|
||||
CapturedTypeConstructorMarker {
|
||||
|
||||
@@ -806,6 +806,8 @@ private fun IrDeclaration.renderDeclarationParentFqn(sb: StringBuilder) {
|
||||
|
||||
fun IrType.render() = RenderIrElementVisitor().renderType(this)
|
||||
|
||||
fun IrSimpleType.render() = (this as IrType).render()
|
||||
|
||||
fun IrTypeArgument.render() =
|
||||
when (this) {
|
||||
is IrStarProjection -> "*"
|
||||
|
||||
Reference in New Issue
Block a user