backend: fix kt6590_identityEquals.kt (#333)

Customize `===` for value types to achive the same behavior as with JVM BE
This commit is contained in:
SvyatoslavScherbina
2017-03-13 20:45:33 +07:00
committed by Nikolay Igotti
parent 20ffd6d90b
commit b803e95c0b
@@ -4,6 +4,7 @@ import org.jetbrains.kotlin.backend.common.BodyLoweringPass
import org.jetbrains.kotlin.backend.konan.Context
import org.jetbrains.kotlin.backend.konan.KonanConfigKeys.Companion.ENABLE_ASSERTIONS
import org.jetbrains.kotlin.backend.konan.descriptors.getKonanInternalFunctions
import org.jetbrains.kotlin.backend.konan.isValueType
import org.jetbrains.kotlin.backend.konan.util.atMostOne
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.ir.descriptors.IrBuiltinOperatorDescriptor
@@ -76,6 +77,8 @@ private class BuiltinOperatorTransformer(val context: Context) : IrElementTransf
lowerEqeq(binary.argument0, binary.argument1, expression.startOffset, expression.endOffset)
}
irBuiltins.eqeqeq -> lowerEqeqeq(expression)
irBuiltins.throwNpe -> IrCallImpl(expression.startOffset, expression.endOffset,
builtIns.getKonanInternalFunctions("ThrowNullPointerException").single())
@@ -86,6 +89,19 @@ private class BuiltinOperatorTransformer(val context: Context) : IrElementTransf
}
}
private fun lowerEqeqeq(expression: IrCall): IrExpression {
val lhs = expression.getValueArgument(0)!!
val rhs = expression.getValueArgument(1)!!
return if (lhs.type.isValueType() && rhs.type.isValueType()) {
// Achieve the same behavior as with JVM BE: if both sides of `===` are values, then compare by value:
lowerEqeq(lhs, rhs, expression.startOffset, expression.endOffset)
// Note: such comparisons are deprecated.
} else {
expression
}
}
private fun lowerEqeq(lhs: IrExpression, rhs: IrExpression, startOffset: Int, endOffset: Int): IrExpression {
// TODO: optimize boxing?