diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrElementToJsExpressionTransformer.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrElementToJsExpressionTransformer.kt index 6a6ba337354..693a479daa7 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrElementToJsExpressionTransformer.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrElementToJsExpressionTransformer.kt @@ -44,11 +44,13 @@ class IrElementToJsExpressionTransformer : BaseIrElementToJsNodeTransformer JsIntLiteral(kind.valueOf(expression)) is IrConstKind.Long -> throw IllegalStateException("Long const should have been lowered at this point") is IrConstKind.Char -> throw IllegalStateException("Char const should have been lowered at this point") - is IrConstKind.Float -> JsDoubleLiteral(kind.valueOf(expression).toDouble()) + is IrConstKind.Float -> JsDoubleLiteral(toDoubleConst(kind.valueOf(expression))) is IrConstKind.Double -> JsDoubleLiteral(kind.valueOf(expression)) } } + private fun toDoubleConst(f: Float) = if (f.isInfinite() || f.isNaN()) f.toDouble() else f.toString().toDouble() + override fun visitStringConcatenation(expression: IrStringConcatenation, context: JsGenerationContext): JsExpression { // TODO revisit return expression.arguments.fold(JsStringLiteral("")) { jsExpr, irExpr -> diff --git a/compiler/testData/codegen/box/constants/float.kt b/compiler/testData/codegen/box/constants/float.kt index 21f1e177099..5c60d382df1 100644 --- a/compiler/testData/codegen/box/constants/float.kt +++ b/compiler/testData/codegen/box/constants/float.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JS_IR fun box(): String { if (1F != 1.toFloat()) return "fail 1" if (1.0F != 1.0.toFloat()) return "fail 2" diff --git a/compiler/testData/codegen/box/controlStructures/forInArray/forInArraySpecializedToUntil.kt b/compiler/testData/codegen/box/controlStructures/forInArray/forInArraySpecializedToUntil.kt index fe1b8ff2934..29235120da1 100644 --- a/compiler/testData/codegen/box/controlStructures/forInArray/forInArraySpecializedToUntil.kt +++ b/compiler/testData/codegen/box/controlStructures/forInArray/forInArraySpecializedToUntil.kt @@ -1,4 +1,5 @@ // IGNORE_BACKEND: JS +// IGNORE_BACKEND: JS_IR // WITH_RUNTIME fun checkByteArray(): Boolean { diff --git a/compiler/testData/codegen/box/strings/constInStringTemplate.kt b/compiler/testData/codegen/box/strings/constInStringTemplate.kt index 0da17a80a02..5595599889d 100644 --- a/compiler/testData/codegen/box/strings/constInStringTemplate.kt +++ b/compiler/testData/codegen/box/strings/constInStringTemplate.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JS_IR // WITH_RUNTIME import kotlin.test.assertEquals