diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 7d5fb0e18dc..8e774ce31a5 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -3809,6 +3809,11 @@ public class ExpressionCodegen extends KtVisitor impleme v.goTo(end); v.mark(ifNull); + Integer leftLineNumber = CodegenUtil.getLineNumberForElement(left, false); + Integer rightLineNumber = CodegenUtil.getLineNumberForElement(expression.getRight(), false); + if (rightLineNumber != null && rightLineNumber.equals(leftLineNumber)) { + v.visitLineNumber(rightLineNumber, ifNull); + } v.pop(); gen(expression.getRight(), exprType, exprKotlinType); v.mark(end); diff --git a/compiler/testData/codegen/box/coroutines/debug/elvisLineNumber.kt b/compiler/testData/codegen/box/coroutines/debug/elvisLineNumber.kt new file mode 100644 index 00000000000..d53ca035e40 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/debug/elvisLineNumber.kt @@ -0,0 +1,42 @@ +// IGNORE_BACKEND: JVM_IR +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// WITH_COROUTINES +// FULL_JDK + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +suspend fun returnsNull() = null + +fun withLineBreak() = builder { + returnsNull() + ?: throw RuntimeException() +} + +fun withoutLineBreak() = builder { + returnsNull() ?: throw RuntimeException() +} + +fun box(): String { + try { + withLineBreak() + return "FAIL 0" + } catch (e: RuntimeException) { + if (e.stackTrace[0].lineNumber != 19) return "FAIL 1 ${e.stackTrace[0].lineNumber}" + } + + try { + withoutLineBreak() + return "FAIL 2" + } catch (e: RuntimeException) { + if (e.stackTrace[0].lineNumber != 23) return "FAIL 3 ${e.stackTrace[0].lineNumber}" + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 84a1a6f41ba..55dde22ae5d 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -6790,6 +6790,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/coroutines/debug/debuggerMetadata.kt"); } + @TestMetadata("elvisLineNumber.kt") + public void testElvisLineNumber() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/debug/elvisLineNumber.kt"); + } + @TestMetadata("firstSuspensionPoint.kt") public void testFirstSuspensionPoint() throws Exception { runTest("compiler/testData/codegen/box/coroutines/debug/firstSuspensionPoint.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 6874c2e4f55..ddedeb9d93d 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -6790,6 +6790,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/coroutines/debug/debuggerMetadata.kt"); } + @TestMetadata("elvisLineNumber.kt") + public void testElvisLineNumber() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/debug/elvisLineNumber.kt"); + } + @TestMetadata("firstSuspensionPoint.kt") public void testFirstSuspensionPoint() throws Exception { runTest("compiler/testData/codegen/box/coroutines/debug/firstSuspensionPoint.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 2eec769c665..acbe6081944 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -6245,6 +6245,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/coroutines/debug/debuggerMetadata.kt"); } + @TestMetadata("elvisLineNumber.kt") + public void testElvisLineNumber() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/debug/elvisLineNumber.kt"); + } + @TestMetadata("firstSuspensionPoint.kt") public void testFirstSuspensionPoint() throws Exception { runTest("compiler/testData/codegen/box/coroutines/debug/firstSuspensionPoint.kt");