[JS IR BE] Check for unbound symbols in type operator lowering

This commit is contained in:
Svyatoslav Kuzmich
2018-08-23 19:56:14 +03:00
parent 437a68daca
commit e0237a4480
2 changed files with 20 additions and 3 deletions
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.SimpleType
import org.jetbrains.kotlin.types.isNullable
private typealias MemberToTransformer = MutableMap<SimpleMemberKey, (IrCall) -> IrExpression>
private typealias SymbolToTransformer = MutableMap<IrFunctionSymbol, (IrCall) -> IrExpression>
@@ -572,7 +573,8 @@ fun translateEquals(lhs: IrType, rhs: IrType): EqualityLoweringType = when {
lhs.isNullableBoolean() -> translateEqualsForNullableBoolean(rhs)
lhs.isString() -> translateEqualsForString(rhs)
lhs.isNullableString() -> translateEqualsForNullableString(rhs)
lhs.isNullable() -> RuntimeFunctionCall
// TODO: Fix unbound symbols (in inline)
lhs.toKotlinType().isNullable() -> RuntimeFunctionCall
else -> RuntimeOrMethodCall
}
@@ -185,6 +185,14 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : FileLoweringPass {
}
private fun generateTypeCheck(argument: IrExpression, toType: IrType): IrExpression {
// TODO: Fix unbound symbols (in inline)
toType.classifierOrNull?.apply {
if (!isBound) {
return argument
}
}
val toNotNullable = toType.makeNotNull()
val instanceCheck = generateTypeCheckNonNull(argument, toNotNullable)
val isFromNullable = argument.type.isNullable()
@@ -222,8 +230,15 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : FileLoweringPass {
}
private fun generateTypeCheckWithTypeParameter(argument: IrExpression, toType: IrType): IrExpression {
val typeParameter =
(toType.classifierOrNull as? IrTypeParameterSymbol)?.owner ?: error("expected type parameter, but $toType")
val typeParameterSymbol =
(toType.classifierOrNull as? IrTypeParameterSymbol) ?: error("expected type parameter, but $toType")
// TODO: Stop creating unbound symbols inline:
// DeepCopyIrTreeWithDescriptors.copy() -> ... -> ClassifierDescriptor.getSymbol()
if (!typeParameterSymbol.isBound) {
return argument
}
val typeParameter = typeParameterSymbol.owner
assert(!typeParameter.isReified) { "reified parameters have to be lowered before" }