[IR] Not try Null constant in fold constant

^KT-46859 fixed
This commit is contained in:
Ilya Goncharov
2021-05-21 19:29:06 +03:00
committed by teamcityserver
parent b18d4af37b
commit c62a965180
10 changed files with 81 additions and 0 deletions
@@ -130,6 +130,7 @@ class FoldConstantLowering(
operationName == "toString" -> constToString(operand)
// Disable toFloat folding on K/JS till `toFloat` is fixed (KT-35422)
operationName == "toFloat" && floatSpecial -> return call
operand.kind == IrConstKind.Null -> return call
else -> evaluateUnary(
operationName,
operand.kind.toString(),
@@ -161,6 +162,8 @@ class FoldConstantLowering(
val lhs = coerceToDouble(call.dispatchReceiver as? IrConst<*> ?: return call)
val rhs = coerceToDouble(call.getValueArgument(0) as? IrConst<*> ?: return call)
if (lhs.kind == IrConstKind.Null || rhs.kind == IrConstKind.Null) return call
val evaluated = try {
evaluateBinary(
call.symbol.owner.name.toString(),
@@ -189,6 +192,8 @@ class FoldConstantLowering(
val lhs = call.getValueArgument(0) as? IrConst<*> ?: return call
val rhs = call.getValueArgument(1) as? IrConst<*> ?: return call
if (lhs.kind == IrConstKind.Null || rhs.kind == IrConstKind.Null) return call
val evaluated = try {
val evaluator =
BINARY_OP_TO_EVALUATOR[BinaryOp(lhs.kind.toString(), rhs.kind.toString(), call.symbol.owner.name.toString())] ?: return call