diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ir/IrBuilder.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ir/IrBuilder.kt index 383de9a2de6..bdf553d78c4 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ir/IrBuilder.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ir/IrBuilder.kt @@ -157,9 +157,29 @@ object JsIrBuilder { fun buildBreak(type: IrType, loop: IrLoop) = IrBreakImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, loop) fun buildContinue(type: IrType, loop: IrLoop) = IrContinueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, loop) - fun buildIfElse(type: IrType, cond: IrExpression, thenBranch: IrExpression, elseBranch: IrExpression? = null): IrWhen = buildIfElse( - UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, cond, thenBranch, elseBranch, JsStatementOrigins.SYNTHESIZED_STATEMENT - ) + fun buildIfElse( + type: IrType, + cond: IrExpression, + thenBranch: IrExpression, + elseBranch: IrExpression? = null, + thenBranchStartOffset: Int = cond.startOffset, + thenBranchEndOffset: Int = thenBranch.endOffset, + elseBranchStartOffset: Int = UNDEFINED_OFFSET, + elseBranchEndOffset: Int = elseBranch?.endOffset ?: UNDEFINED_OFFSET, + ): IrWhen = + buildIfElse( + startOffset = UNDEFINED_OFFSET, + endOffset = UNDEFINED_OFFSET, + type = type, + cond = cond, + thenBranch = thenBranch, + elseBranch = elseBranch, + origin = JsStatementOrigins.SYNTHESIZED_STATEMENT, + thenBranchStartOffset = thenBranchStartOffset, + thenBranchEndOffset = thenBranchEndOffset, + elseBranchStartOffset = elseBranchStartOffset, + elseBranchEndOffset = elseBranchEndOffset + ) fun buildIfElse( startOffset: Int, @@ -168,13 +188,17 @@ object JsIrBuilder { cond: IrExpression, thenBranch: IrExpression, elseBranch: IrExpression? = null, - origin: IrStatementOrigin? = null + origin: IrStatementOrigin? = null, + thenBranchStartOffset: Int = cond.startOffset, + thenBranchEndOffset: Int = thenBranch.endOffset, + elseBranchStartOffset: Int = UNDEFINED_OFFSET, + elseBranchEndOffset: Int = elseBranch?.endOffset ?: UNDEFINED_OFFSET, ): IrWhen { val element = IrIfThenElseImpl(startOffset, endOffset, type, origin) - element.branches.add(IrBranchImpl(cond, thenBranch)) + element.branches.add(IrBranchImpl(thenBranchStartOffset, thenBranchEndOffset, cond, thenBranch)) if (elseBranch != null) { - val irTrue = IrConstImpl.boolean(UNDEFINED_OFFSET, UNDEFINED_OFFSET, cond.type, true) - element.branches.add(IrElseBranchImpl(irTrue, elseBranch)) + val irTrue = IrConstImpl.constTrue(UNDEFINED_OFFSET, UNDEFINED_OFFSET, cond.type) + element.branches.add(IrElseBranchImpl(elseBranchStartOffset, elseBranchEndOffset, irTrue, elseBranch)) } return element diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BlockDecomposerLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BlockDecomposerLowering.kt index 3cb1dfb428e..61540533dfc 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BlockDecomposerLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BlockDecomposerLowering.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.backend.common.ir.isPure import org.jetbrains.kotlin.descriptors.DescriptorVisibilities import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrStatement +import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder @@ -424,13 +425,17 @@ class BlockDecomposerTransformer( isElseBranch(orig) -> (res as? IrBlock)?.statements ?: listOf(res) else -> listOf( JsIrBuilder.buildIfElse( - orig.startOffset, - orig.endOffset, - unitType, - condValue, - res, - elseBlock, - expression.origin + startOffset = UNDEFINED_OFFSET, + endOffset = UNDEFINED_OFFSET, + type = unitType, + cond = condValue, + thenBranch = res, + elseBranch = elseBlock, + origin = expression.origin, + thenBranchStartOffset = orig.startOffset, + thenBranchEndOffset = orig.endOffset, + elseBranchStartOffset = UNDEFINED_OFFSET, + elseBranchEndOffset = UNDEFINED_OFFSET, ) ) } diff --git a/compiler/testData/debug/stepping/if.kt b/compiler/testData/debug/stepping/if.kt index 0ed2c9bef0a..861ba9c5ca4 100644 --- a/compiler/testData/debug/stepping/if.kt +++ b/compiler/testData/debug/stepping/if.kt @@ -26,6 +26,6 @@ inline fun getB(): Int { // EXPECTATIONS JS_IR // test.kt:14 box -// test.kt:5 box +// test.kt:4 box // test.kt:11 getA // test.kt:14 box diff --git a/compiler/testData/debug/stepping/ifWithInlineInCondition.kt b/compiler/testData/debug/stepping/ifWithInlineInCondition.kt index dcb85cdadd3..a051978baf0 100644 --- a/compiler/testData/debug/stepping/ifWithInlineInCondition.kt +++ b/compiler/testData/debug/stepping/ifWithInlineInCondition.kt @@ -66,13 +66,13 @@ fun nop() {} // test.kt:8 box // test.kt:24 box // test.kt:9 box -// test.kt:10 box +// test.kt:7 box // test.kt:11 box // test.kt:30 nop // test.kt:24 box // test.kt:16 box // test.kt:27 box -// test.kt:15 box +// test.kt:14 box // test.kt:19 box // test.kt:30 nop // test.kt:21 box diff --git a/js/js.translator/testData/lineNumbers/catch.kt b/js/js.translator/testData/lineNumbers/catch.kt index b8728f4f9a6..1cd127cc74b 100644 --- a/js/js.translator/testData/lineNumbers/catch.kt +++ b/js/js.translator/testData/lineNumbers/catch.kt @@ -20,4 +20,4 @@ fun bar() { } // LINES(JS): 1 11 3 3 5 5 6 6 8 8 9 9 2 2 * 13 20 15 15 18 18 -// LINES(JS_IR): 1 1 3 3 5 * 6 6 * 8 9 9 * 13 13 15 15 17 18 18 +// LINES(JS_IR): 1 1 3 3 5 5 6 6 8 8 9 9 * 13 13 15 15 17 18 18 diff --git a/js/js.translator/testData/lineNumbers/dataClass.kt b/js/js.translator/testData/lineNumbers/dataClass.kt index c3f0def5264..ff6c6889ae4 100644 --- a/js/js.translator/testData/lineNumbers/dataClass.kt +++ b/js/js.translator/testData/lineNumbers/dataClass.kt @@ -4,4 +4,4 @@ data class A( ) // LINES(JS): 1 2 3 * 1 2 2 1 3 3 1 1 1 2 3 1 1 1 2 3 1 1 1 2 3 1 1 1 1 1 2 3 -// LINES(JS_IR): 1 1 2 2 3 3 2 2 2 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 * 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +// LINES(JS_IR): 1 1 2 2 3 3 2 2 2 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 * 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 diff --git a/js/js.translator/testData/lineNumbers/isOperator.kt b/js/js.translator/testData/lineNumbers/isOperator.kt index 219244f4fc0..8afb25627c8 100644 --- a/js/js.translator/testData/lineNumbers/isOperator.kt +++ b/js/js.translator/testData/lineNumbers/isOperator.kt @@ -11,5 +11,5 @@ inline fun foo(): Boolean { return true } -// LINES(JS): 3 7 4 4 4 10 10 4 11 4 5 5 9 12 10 10 11 11 * 1 * 1 -// LINES(JS_IR): 1 1 1 1 1 1 1 1 * 3 3 * 4 * 4 * 10 10 11 11 4 4 * 5 5 9 9 10 10 11 11 * 1 +// LINES(JS): 3 7 4 4 4 10 10 4 11 4 5 5 9 12 10 10 11 11 * 1 * 1 +// LINES(JS_IR): 1 1 1 1 1 1 1 1 * 3 3 * 4 4 * 4 * 10 10 11 11 4 4 4 5 5 9 9 10 10 11 11 * 1 diff --git a/js/js.translator/testData/lineNumbers/lastExpressionInInlineLambda.kt b/js/js.translator/testData/lineNumbers/lastExpressionInInlineLambda.kt index 7498ba693b3..ed2218a7b39 100644 --- a/js/js.translator/testData/lineNumbers/lastExpressionInInlineLambda.kt +++ b/js/js.translator/testData/lineNumbers/lastExpressionInInlineLambda.kt @@ -24,5 +24,5 @@ fun baz() = "baz" fun boo() = "boo" -// LINES(JS): 1 17 9 4 6 6 7 7 3 3 3 * 13 12 13 13 14 19 21 20 20 23 23 23 25 25 25 -// LINES(JS_IR): 1 1 * 2 * 20 * 4 6 * 7 * 3 20 20 * 11 * 20 * 12 12 12 13 14 20 20 19 19 20 20 23 23 23 23 25 25 25 25 +// LINES(JS): 1 17 9 4 6 6 7 7 3 3 3 * 13 12 13 13 14 19 21 20 20 23 23 23 25 25 25 +// LINES(JS_IR): 1 1 * 2 * 20 * 4 6 * 6 7 * 3 20 20 * 11 * 20 * 12 12 12 13 14 20 20 19 19 20 20 23 23 23 23 25 25 25 25 diff --git a/js/js.translator/testData/lineNumbers/whenIs.kt b/js/js.translator/testData/lineNumbers/whenIs.kt index fe3412e6710..baefb5cd254 100644 --- a/js/js.translator/testData/lineNumbers/whenIs.kt +++ b/js/js.translator/testData/lineNumbers/whenIs.kt @@ -14,4 +14,4 @@ open class A open class B : A() // LINES(JS): 1 10 2 2 2 2 3 3 4 4 5 5 6 6 8 8 12 * 14 14 -// LINES(JS_IR): 1 1 2 2 3 4 4 5 6 6 8 8 12 12 14 14 14 +// LINES(JS_IR): 1 1 2 2 3 3 4 4 5 5 6 6 8 8 12 12 14 14 14