diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/CheckIrElementVisitor.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/CheckIrElementVisitor.kt index ca174041a35..42e5cbfc970 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/CheckIrElementVisitor.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/CheckIrElementVisitor.kt @@ -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() + val checkedTypes = mutableSetOf() 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) + } } \ No newline at end of file diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/utils/kotlinTypeBasedUtils.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/utils/kotlinTypeBasedUtils.kt index 7be71d9e39c..a16da585e9d 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/utils/kotlinTypeBasedUtils.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/utils/kotlinTypeBasedUtils.kt @@ -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.commonSupertype() = CommonSupertypes.commonSupertype(map(IrType::toKotlinType)).toIrType()!! +fun List.commonSupertype(symbolTable: SymbolTable) = + CommonSupertypes.commonSupertype(map(IrType::toKotlinType)).toIrType(symbolTable)!! @Deprecated("Use pure Ir helper") fun IrType.isSubtypeOf(superType: IrType) = toKotlinType().isSubtypeOf(superType.toKotlinType()) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/AutoboxingTransformer.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/AutoboxingTransformer.kt index 7933b3552d2..f70deea349f 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/AutoboxingTransformer.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/AutoboxingTransformer.kt @@ -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 diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/MultipleCatchesLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/MultipleCatchesLowering.kt index 84293a9f0e6..aa77909ea5e 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/MultipleCatchesLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/MultipleCatchesLowering.kt @@ -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) = types.commonSupertype().also { + private fun mergeTypes(types: List) = types.commonSupertype(context.symbolTable).also { assert(it.isSubtypeOf(context.irBuiltIns.throwableType) || it is IrDynamicType) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/InlineClasses.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/InlineClasses.kt index 92c92b04924..1f3e888e3a7 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/InlineClasses.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/InlineClasses.kt @@ -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())