[IR] Make IrClassifierSymbol a sealed interface
This commit is contained in:
committed by
Space Team
parent
6f20ac4f38
commit
1a371350ea
+6
-7
@@ -16,6 +16,8 @@ import org.jetbrains.kotlin.ir.declarations.IrProperty
|
||||
import org.jetbrains.kotlin.ir.declarations.inlineClassRepresentation
|
||||
import org.jetbrains.kotlin.ir.declarations.isSingleFieldValueClass
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrScriptSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrFail
|
||||
@@ -284,13 +286,10 @@ internal object IrTypeInlineClassesSupport : InlineClassesSupport<IrClass, IrTyp
|
||||
}
|
||||
}
|
||||
|
||||
override fun computeFullErasure(type: IrType): Sequence<IrClass> {
|
||||
val classifier = type.classifierOrFail
|
||||
return when (classifier) {
|
||||
is IrClassSymbol -> sequenceOf(classifier.owner)
|
||||
is IrTypeParameterSymbol -> classifier.owner.superTypes.asSequence().flatMap { computeFullErasure(it) }
|
||||
else -> error(classifier)
|
||||
}
|
||||
override fun computeFullErasure(type: IrType): Sequence<IrClass> = when (val classifier = type.classifierOrFail) {
|
||||
is IrClassSymbol -> sequenceOf(classifier.owner)
|
||||
is IrTypeParameterSymbol -> classifier.owner.superTypes.asSequence().flatMap { computeFullErasure(it) }
|
||||
is IrScriptSymbol -> classifier.unexpectedSymbolKind<IrClassifierSymbol>()
|
||||
}
|
||||
|
||||
override fun hasInlineModifier(clazz: IrClass): Boolean = clazz.isSingleFieldValueClass
|
||||
|
||||
+1
-1
@@ -119,7 +119,7 @@ internal class ExpectToActualDefaultValueCopier(private val irModule: IrModuleFr
|
||||
override fun getReferencedClassifier(symbol: IrClassifierSymbol): IrClassifierSymbol = when (symbol) {
|
||||
is IrClassSymbol -> getReferencedClass(symbol)
|
||||
is IrTypeParameterSymbol -> remapExpectTypeParameter(symbol).symbol
|
||||
else -> error("Unexpected symbol $symbol ${symbol.descriptor}")
|
||||
is IrScriptSymbol -> symbol.unexpectedSymbolKind<IrClassifierSymbol>()
|
||||
}
|
||||
|
||||
override fun getReferencedConstructor(symbol: IrConstructorSymbol) =
|
||||
|
||||
+3
-1
@@ -15,6 +15,8 @@ import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrScriptSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
@@ -65,7 +67,7 @@ internal class KTypeGenerator(
|
||||
// Leave upper bounds of non-reified type parameters as is, even if they are reified themselves.
|
||||
irKTypeParameter(classifier.owner, leaveReifiedForLater = false, seenTypeParameters = seenTypeParameters)
|
||||
}
|
||||
else -> TODO("Unexpected classifier: $classifier")
|
||||
is IrScriptSymbol -> classifier.unexpectedSymbolKind<IrClassifierSymbol>()
|
||||
}
|
||||
|
||||
return irKTypeImpl(
|
||||
|
||||
+3
-1
@@ -14,6 +14,8 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrTypeOperator
|
||||
import org.jetbrains.kotlin.ir.expressions.IrTypeOperatorCall
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrScriptSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
@@ -36,7 +38,7 @@ internal fun IrType.erasure(): IrType {
|
||||
// In the second case, there is only a single supertype.
|
||||
classifier.owner.superTypes.first().erasure()
|
||||
}
|
||||
else -> TODO(classifier.toString())
|
||||
is IrScriptSymbol -> classifier.unexpectedSymbolKind<IrClassifierSymbol>()
|
||||
}
|
||||
|
||||
return upperBound.mergeNullability(this)
|
||||
|
||||
+3
-7
@@ -27,10 +27,7 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrVariableSymbolImpl
|
||||
@@ -172,8 +169,7 @@ fun IrFunctionAccessExpression.addArguments(args: Map<IrValueParameter, IrExpres
|
||||
fun IrType.substitute(map: Map<IrTypeParameterSymbol, IrType>): IrType {
|
||||
if (this !is IrSimpleType) return this
|
||||
|
||||
val classifier = this.classifier
|
||||
return when (classifier) {
|
||||
return when (val classifier = this.classifier) {
|
||||
is IrTypeParameterSymbol ->
|
||||
map[classifier]?.mergeNullability(this) ?: this
|
||||
is IrClassSymbol -> if (this.arguments.isEmpty()) {
|
||||
@@ -187,7 +183,7 @@ fun IrType.substitute(map: Map<IrTypeParameterSymbol, IrType>): IrType {
|
||||
}
|
||||
IrSimpleTypeImpl(classifier, nullability, newArguments, annotations)
|
||||
}
|
||||
else -> error(classifier)
|
||||
is IrScriptSymbol -> classifier.unexpectedSymbolKind<IrClassifierSymbol>()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user