Generate line numbers for RHS of elvis expression if both LHS and RHS

are at the same line.
 #KT-32689 Fixed
This commit is contained in:
Ilmir Usmanov
2019-07-22 15:24:37 +03:00
parent 1f36f60f43
commit 56b6b957d1
5 changed files with 62 additions and 0 deletions
@@ -3809,6 +3809,11 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> 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);
@@ -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"
}
@@ -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");
@@ -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");
@@ -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");