diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt index fd3ac1f8449..68f46ef7ba1 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt @@ -262,12 +262,12 @@ class MethodInliner( } val firstLine = info.node.node.instructions.asSequence().mapNotNull { it as? LineNumberNode }.firstOrNull()?.line ?: -1 - if (currentLineNumber >= 0 && firstLine == currentLineNumber) { + if ((info is DefaultLambda != overrideLineNumber) && currentLineNumber >= 0 && firstLine == currentLineNumber) { // This can happen in two cases: // 1. `someInlineOnlyFunction { singleLineLambda }`: in this case line numbers are removed // from the inline function, so the entirety of its bytecode has the line number of // the call site; - // 2. `inline fun someFunction(defaultLambda: ... = { ... }) = singleLineExpression`: + // 2. `inline fun someFunction(defaultLambda: ... = { ... }) = something(defaultLambda())`: // all of `someFunction`, including `defaultLambda` if no value is provided at call site, // has the line number of the declaration. // In those cases the debugger is unable to observe the boundary between the body of the function @@ -312,10 +312,16 @@ class MethodInliner( setLambdaInlining(false) addInlineMarker(this, false) - if (overrideLineNumber) { + if (currentLineNumber != -1) { val endLabel = Label() mv.visitLabel(endLabel) - mv.visitLineNumber(currentLineNumber, endLabel) + if (overrideLineNumber) { + // This is from the function we're inlining into, so no need to remap. + mv.visitLineNumber(currentLineNumber, endLabel) + } else { + // Need to go through the superclass here to properly remap the line number via `sourceMapper`. + super.visitLineNumber(currentLineNumber, endLabel) + } } } else if (isAnonymousConstructorCall(owner, name)) { //TODO add method //TODO add proper message diff --git a/compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/nopInlineFuns.kt b/compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/nopInlineFuns.kt index 8632b28e9dc..835ced821c1 100644 --- a/compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/nopInlineFuns.kt +++ b/compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/nopInlineFuns.kt @@ -12,7 +12,7 @@ inline fun inlineFunInt(f: () -> Int): Int { inline fun inlineFunVoid(f: () -> Unit): Unit { val a = 1 - return f() + return f() // return replaced with nop to stop here *after* calling f } fun simpleFunInt(f: () -> Int): Int { @@ -20,7 +20,7 @@ fun simpleFunInt(f: () -> Int): Int { } fun simpleFunVoid(f: () -> Unit): Unit { - return f() + return f() // return replaced with nop to stop here *after* calling f } -// 0 NOP +// 2 NOP diff --git a/compiler/testData/codegen/bytecodeText/inline/linenumberForOneParametersArgumentCall.kt b/compiler/testData/codegen/bytecodeText/inline/linenumberForOneParametersArgumentCall.kt index 43d605999dd..05b797eda82 100644 --- a/compiler/testData/codegen/bytecodeText/inline/linenumberForOneParametersArgumentCall.kt +++ b/compiler/testData/codegen/bytecodeText/inline/linenumberForOneParametersArgumentCall.kt @@ -1,13 +1,13 @@ fun box() { - lookAtMe { - val c = "c" - } + lookAtMe { // 1 + val c = "c" // 4 + } // 5 (nop) } inline fun lookAtMe(f: (String) -> Unit) { - val a = "a" - f(a) // Should be no unneeded nops on this line, that might be generated for zero-parameters lambda -} + val a = "a" // 2 + f(a) // 3 before call, 6 after call (nop) +} // 7 (nop) -// 2 NOP +// 3 NOP diff --git a/compiler/testData/debug/stepping/functionCallWithInlinedLambdaParam.kt b/compiler/testData/debug/stepping/functionCallWithInlinedLambdaParam.kt index 2fed22e5380..b88e09f2b3b 100644 --- a/compiler/testData/debug/stepping/functionCallWithInlinedLambdaParam.kt +++ b/compiler/testData/debug/stepping/functionCallWithInlinedLambdaParam.kt @@ -21,11 +21,13 @@ inline fun foo(f: () -> Unit) { // test.kt:15 box // test.kt:5 box // test.kt:6 box +// test.kt:15 box // test.kt:16 box // test.kt:8 box // test.kt:14 box // test.kt:15 box // test.kt:9 box // test.kt:10 box +// test.kt:15 box // test.kt:16 box // test.kt:11 box diff --git a/compiler/testData/debug/stepping/inTheEndOfLambdaArgumentOfInlineCall.kt b/compiler/testData/debug/stepping/inTheEndOfLambdaArgumentOfInlineCall.kt index c5be5712414..c482f310249 100644 --- a/compiler/testData/debug/stepping/inTheEndOfLambdaArgumentOfInlineCall.kt +++ b/compiler/testData/debug/stepping/inTheEndOfLambdaArgumentOfInlineCall.kt @@ -30,5 +30,6 @@ fun nop() {} // test.kt:19 nop // test.kt:17 box // test.kt:7 box +// test.kt:12 box // test.kt:13 box // test.kt:8 box diff --git a/compiler/testData/debug/stepping/inlineCallableReference.kt b/compiler/testData/debug/stepping/inlineCallableReference.kt index 6d3d8bec734..264b61fac0c 100644 --- a/compiler/testData/debug/stepping/inlineCallableReference.kt +++ b/compiler/testData/debug/stepping/inlineCallableReference.kt @@ -21,6 +21,7 @@ inline fun f(block: () -> Unit) { // test.kt:15 box // test.kt:5 box // test.kt:6 box +// test.kt:15 box // test.kt:16 box // test.kt:7 box // test.kt:8 box @@ -29,5 +30,6 @@ inline fun f(block: () -> Unit) { // test.kt:15 box // test.kt:10 box // test.kt:11 box +// test.kt:15 box // test.kt:16 box // test.kt:12 box \ No newline at end of file diff --git a/compiler/testData/debug/stepping/inlineNamedCallableReference.kt b/compiler/testData/debug/stepping/inlineNamedCallableReference.kt index 3eed8a1a043..3f5fe4e196d 100644 --- a/compiler/testData/debug/stepping/inlineNamedCallableReference.kt +++ b/compiler/testData/debug/stepping/inlineNamedCallableReference.kt @@ -16,5 +16,6 @@ fun g() {} // test.kt:8 box // test.kt:4 box // test.kt:11 g +// test.kt:8 box // test.kt:9 box // test.kt:5 box diff --git a/compiler/testData/debug/stepping/inlineSimpleCall.kt b/compiler/testData/debug/stepping/inlineSimpleCall.kt index 695b2c12624..96d1b46c153 100644 --- a/compiler/testData/debug/stepping/inlineSimpleCall.kt +++ b/compiler/testData/debug/stepping/inlineSimpleCall.kt @@ -27,11 +27,13 @@ fun box() { // test.kt:4 box // test.kt:9 box // test.kt:10 box +// test.kt:4 box // test.kt:5 box // test.kt:12 box // test.kt:4 box // test.kt:13 box // test.kt:14 box +// test.kt:4 box // test.kt:5 box // test.kt:16 box // test.kt:4 box @@ -40,7 +42,9 @@ fun box() { // test.kt:4 box // test.kt:20 box // test.kt:21 box +// test.kt:4 box // test.kt:5 box // test.kt:22 box +// test.kt:4 box // test.kt:5 box // test.kt:23 box diff --git a/compiler/testData/debug/stepping/lambdaStepInline.kt b/compiler/testData/debug/stepping/lambdaStepInline.kt index eaa72c1058e..c2121dbfdca 100644 --- a/compiler/testData/debug/stepping/lambdaStepInline.kt +++ b/compiler/testData/debug/stepping/lambdaStepInline.kt @@ -17,7 +17,9 @@ fun box(): String { // test.kt:8 box // test.kt:4 box // test.kt:8 box +// test.kt:4 box // test.kt:9 box // test.kt:4 box // test.kt:10 box +// test.kt:4 box // test.kt:13 box diff --git a/compiler/testData/debug/stepping/lambdaStepInlineWithDefaults.kt b/compiler/testData/debug/stepping/lambdaStepInlineWithDefaults.kt index adfe6fad1c8..c94f68281df 100644 --- a/compiler/testData/debug/stepping/lambdaStepInlineWithDefaults.kt +++ b/compiler/testData/debug/stepping/lambdaStepInlineWithDefaults.kt @@ -22,8 +22,10 @@ fun box(): String { // test.kt:3 box // test.kt:4 box // test.kt:3 box +// test.kt:4 box // test.kt:16 box // test.kt:7 box // test.kt:11 box // test.kt:8 box +// test.kt:11 box // test.kt:17 box diff --git a/compiler/testData/debug/stepping/linenumberForOneParametersArgumentCall.kt b/compiler/testData/debug/stepping/linenumberForOneParametersArgumentCall.kt index efedb3bb168..c6ce92c52c0 100644 --- a/compiler/testData/debug/stepping/linenumberForOneParametersArgumentCall.kt +++ b/compiler/testData/debug/stepping/linenumberForOneParametersArgumentCall.kt @@ -17,5 +17,6 @@ inline fun lookAtMe(f: (String) -> Unit) { // test.kt:11 box // test.kt:5 box // test.kt:6 box +// test.kt:11 box // test.kt:12 box // test.kt:7 box \ No newline at end of file diff --git a/compiler/testData/debug/stepping/nestedInline.kt b/compiler/testData/debug/stepping/nestedInline.kt index 88054d01572..7bad04b3d40 100644 --- a/compiler/testData/debug/stepping/nestedInline.kt +++ b/compiler/testData/debug/stepping/nestedInline.kt @@ -53,9 +53,11 @@ inline fun html(init: () -> Unit) { // 1.kt:34 box // test.kt:11 box // test.kt:12 box +// 1.kt:34 box // 1.kt:35 box // 1.kt:37 box // test.kt:13 box +// 1.kt:29 box // 1.kt:30 box // 1.kt:41 box // test.kt:15 box diff --git a/compiler/testData/debug/stepping/noParametersArgumentCallInExpression.kt b/compiler/testData/debug/stepping/noParametersArgumentCallInExpression.kt index b76c5b7ba06..dbe665cdc16 100644 --- a/compiler/testData/debug/stepping/noParametersArgumentCallInExpression.kt +++ b/compiler/testData/debug/stepping/noParametersArgumentCallInExpression.kt @@ -16,5 +16,6 @@ inline fun lookAtMe(f: () -> Int) { // test.kt:10 box // test.kt:11 box // test.kt:5 box +// test.kt:11 box // test.kt:12 box // test.kt:7 box diff --git a/compiler/testData/debug/stepping/simpleSmap.kt b/compiler/testData/debug/stepping/simpleSmap.kt index ff9ba8e39f6..3f7d151c408 100644 --- a/compiler/testData/debug/stepping/simpleSmap.kt +++ b/compiler/testData/debug/stepping/simpleSmap.kt @@ -15,5 +15,6 @@ fun box() { // test.kt:4 box // test.kt:9 box // test.kt:10 box +// test.kt:4 box // test.kt:5 box // test.kt:11 box