[JVM] Improve debug step behavior around lambdas.
- Add tests to clarify problematic behavior - Avoid line numbers on return instructions of lambdas without explicit returns
This commit is contained in:
committed by
max-kammerer
parent
fc7d667282
commit
7ec4c9990a
@@ -1759,8 +1759,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
if (!endsWithReturn(expr)) {
|
||||
if (isLambdaVoidBody(expr, typeForExpression)) {
|
||||
markLineNumber((KtFunctionLiteral) expr.getParent(), true);
|
||||
}
|
||||
else {
|
||||
} else if (!isLambdaBody(expr)){
|
||||
markLineNumber(expr, true);
|
||||
}
|
||||
|
||||
@@ -1782,13 +1781,14 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
}
|
||||
|
||||
private static boolean isLambdaVoidBody(@NotNull KtElement bodyExpression, @NotNull Type returnType) {
|
||||
return isLambdaBody(bodyExpression) && Type.VOID_TYPE.equals(returnType);
|
||||
}
|
||||
|
||||
private static boolean isLambdaBody(@NotNull KtElement bodyExpression) {
|
||||
if (bodyExpression instanceof KtBlockExpression) {
|
||||
PsiElement parent = bodyExpression.getParent();
|
||||
if (parent instanceof KtFunctionLiteral) {
|
||||
return Type.VOID_TYPE.equals(returnType);
|
||||
}
|
||||
return parent instanceof KtFunctionLiteral;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -133,7 +133,6 @@ test/_1Kt$lParams$1
|
||||
71#2,2:12
|
||||
30#2:15
|
||||
51#3:14
|
||||
69#3:16
|
||||
*E
|
||||
*S KotlinDebug
|
||||
*F
|
||||
@@ -144,5 +143,4 @@ _2Kt
|
||||
6#1,2:12
|
||||
6#1:15
|
||||
6#1:14
|
||||
6#1:16
|
||||
*E
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
// FILE: test.kt
|
||||
inline fun foo(stringMaker: () -> String): String {
|
||||
return stringMaker()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
foo { "OK "}
|
||||
foo {
|
||||
"OK"
|
||||
// Comment
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// LINENUMBERS
|
||||
// test.kt:8
|
||||
// test.kt:4
|
||||
// test.kt:8
|
||||
// test.kt:9
|
||||
// test.kt:4
|
||||
// test.kt:10
|
||||
// test.kt:13
|
||||
@@ -0,0 +1,42 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// FILE: test.kt
|
||||
inline fun foo(stringMaker: () -> String = { "OK" }): String {
|
||||
return stringMaker()
|
||||
}
|
||||
|
||||
inline fun foo2(stringMaker: () -> String = {
|
||||
"OK"
|
||||
// Comment
|
||||
}): String {
|
||||
return stringMaker()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
foo()
|
||||
foo2()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// The IR Backend does the following:
|
||||
// test.kt:15
|
||||
// test.kt:3
|
||||
// test.kt:4
|
||||
// test.kt:3
|
||||
// test.kt:3 <---
|
||||
// test.kt:16
|
||||
// test.kt:7
|
||||
// test.kt:11
|
||||
// test.kt:8
|
||||
// test.kt:7 <---
|
||||
// test.kt:17
|
||||
|
||||
// LINENUMBERS
|
||||
// test.kt:15
|
||||
// test.kt:3
|
||||
// test.kt:4
|
||||
// test.kt:3
|
||||
// test.kt:16
|
||||
// test.kt:7
|
||||
// test.kt:11
|
||||
// test.kt:8
|
||||
// test.kt:17
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
// FILE: test.kt
|
||||
fun box(): String {
|
||||
run { "O" + "K" }
|
||||
run {
|
||||
"O" + "K"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// LINENUMBERS
|
||||
// test.kt:4
|
||||
// test.kt:5
|
||||
// test.kt:6
|
||||
// test.kt:5
|
||||
// test.kt:8
|
||||
+18
@@ -91,6 +91,18 @@ public class IrSteppingTestGenerated extends AbstractIrSteppingTest {
|
||||
runTest("compiler/testData/debug/stepping/inlineNamedCallableReference.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaStepInline.kt")
|
||||
public void testLambdaStepInline() throws Exception {
|
||||
runTest("compiler/testData/debug/stepping/lambdaStepInline.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaStepInlineWithDefaults.kt")
|
||||
public void testLambdaStepInlineWithDefaults() throws Exception {
|
||||
runTest("compiler/testData/debug/stepping/lambdaStepInlineWithDefaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("namedCallableReference.kt")
|
||||
public void testNamedCallableReference() throws Exception {
|
||||
@@ -132,4 +144,10 @@ public class IrSteppingTestGenerated extends AbstractIrSteppingTest {
|
||||
public void testThrowException() throws Exception {
|
||||
runTest("compiler/testData/debug/stepping/throwException.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("voidLambdaStepInline.kt")
|
||||
public void testVoidLambdaStepInline() throws Exception {
|
||||
runTest("compiler/testData/debug/stepping/voidLambdaStepInline.kt");
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -91,6 +91,18 @@ public class SteppingTestGenerated extends AbstractSteppingTest {
|
||||
runTest("compiler/testData/debug/stepping/inlineNamedCallableReference.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaStepInline.kt")
|
||||
public void testLambdaStepInline() throws Exception {
|
||||
runTest("compiler/testData/debug/stepping/lambdaStepInline.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaStepInlineWithDefaults.kt")
|
||||
public void testLambdaStepInlineWithDefaults() throws Exception {
|
||||
runTest("compiler/testData/debug/stepping/lambdaStepInlineWithDefaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("namedCallableReference.kt")
|
||||
public void testNamedCallableReference() throws Exception {
|
||||
@@ -132,4 +144,10 @@ public class SteppingTestGenerated extends AbstractSteppingTest {
|
||||
public void testThrowException() throws Exception {
|
||||
runTest("compiler/testData/debug/stepping/throwException.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("voidLambdaStepInline.kt")
|
||||
public void testVoidLambdaStepInline() throws Exception {
|
||||
runTest("compiler/testData/debug/stepping/voidLambdaStepInline.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user