[JS IR BE] Fix inline classes workarounds
- Remove uninitialized return type check - Remove unbound classifier symbol check
This commit is contained in:
+22
-4
@@ -22,12 +22,10 @@ import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrDynamicType
|
||||
import org.jetbrains.kotlin.ir.types.isUnit
|
||||
import org.jetbrains.kotlin.ir.types.makeNullable
|
||||
import org.jetbrains.kotlin.ir.types.toKotlinType
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.isAnnotationClass
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.ir.util.superTypes
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
@@ -41,6 +39,7 @@ class CheckIrElementVisitor(
|
||||
) : IrElementVisitorVoid {
|
||||
|
||||
val set = mutableSetOf<IrElement>()
|
||||
val checkedTypes = mutableSetOf<IrType>()
|
||||
|
||||
override fun visitElement(element: IrElement) {
|
||||
if (config.ensureAllNodesAreDifferent) {
|
||||
@@ -290,4 +289,23 @@ class CheckIrElementVisitor(
|
||||
expression.setter?.ensureBound(expression)
|
||||
}
|
||||
|
||||
override fun visitExpression(expression: IrExpression) {
|
||||
checkType(expression.type, expression)
|
||||
super.visitExpression(expression)
|
||||
}
|
||||
|
||||
private fun checkType(type: IrType, element: IrElement) {
|
||||
if (type in checkedTypes)
|
||||
return
|
||||
|
||||
when (type) {
|
||||
is IrSimpleType -> {
|
||||
if (!type.classifier.isBound) {
|
||||
reportError(element, "Type: ${type.render()} has unbound classifier")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkedTypes.add(type)
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.toIrType
|
||||
import org.jetbrains.kotlin.ir.types.toKotlinType
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.types.CommonSupertypes
|
||||
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
||||
@@ -23,7 +24,8 @@ fun IrType.isPrimitiveArray() = KotlinBuiltIns.isPrimitiveArray(toKotlinType())
|
||||
fun IrType.getPrimitiveArrayElementType() = KotlinBuiltIns.getPrimitiveArrayElementType(toKotlinType())
|
||||
|
||||
@Deprecated("Use pure Ir helper")
|
||||
fun List<IrType>.commonSupertype() = CommonSupertypes.commonSupertype(map(IrType::toKotlinType)).toIrType()!!
|
||||
fun List<IrType>.commonSupertype(symbolTable: SymbolTable) =
|
||||
CommonSupertypes.commonSupertype(map(IrType::toKotlinType)).toIrType(symbolTable)!!
|
||||
|
||||
@Deprecated("Use pure Ir helper")
|
||||
fun IrType.isSubtypeOf(superType: IrType) = toKotlinType().isSubtypeOf(superType.toKotlinType())
|
||||
|
||||
+1
-6
@@ -37,12 +37,7 @@ class AutoboxingTransformer(val context: JsIrBackendContext) : AbstractValueUsag
|
||||
if (this.symbol.owner.let { it is IrSimpleFunction && it.isSuspend }) {
|
||||
irBuiltIns.anyNType
|
||||
} else {
|
||||
try {
|
||||
this.symbol.owner.returnType
|
||||
} catch (e: kotlin.UninitializedPropertyAccessException) {
|
||||
// TODO: Fix lateinit return types
|
||||
this.type
|
||||
}
|
||||
this.symbol.owner.returnType
|
||||
}
|
||||
}
|
||||
is IrGetField -> this.symbol.owner.type
|
||||
|
||||
+1
-1
@@ -125,7 +125,7 @@ class MultipleCatchesLowering(val context: JsIrBackendContext) : FileLoweringPas
|
||||
private fun buildImplicitCast(value: IrExpression, toType: IrType, toTypeSymbol: IrClassifierSymbol) =
|
||||
JsIrBuilder.buildTypeOperator(toType, IrTypeOperator.IMPLICIT_CAST, value, toType, toTypeSymbol)
|
||||
|
||||
private fun mergeTypes(types: List<IrType>) = types.commonSupertype().also {
|
||||
private fun mergeTypes(types: List<IrType>) = types.commonSupertype(context.symbolTable).also {
|
||||
assert(it.isSubtypeOf(context.irBuiltIns.throwableType) || it is IrDynamicType)
|
||||
}
|
||||
|
||||
|
||||
@@ -48,10 +48,6 @@ fun IrType.isInlined(): Boolean = this.getInlinedClass() != null
|
||||
private tailrec fun erase(type: IrType): IrClass? {
|
||||
val classifier = type.classifierOrFail
|
||||
|
||||
// TODO: Fix unbound symbols
|
||||
if (!classifier.isBound)
|
||||
return null
|
||||
|
||||
return when (classifier) {
|
||||
is IrClassSymbol -> classifier.owner
|
||||
is IrTypeParameterSymbol -> erase(classifier.owner.superTypes.first())
|
||||
|
||||
Reference in New Issue
Block a user