diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index de59cffb26a..ae2b06043f7 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -1759,8 +1759,7 @@ public class ExpressionCodegen extends KtVisitor 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 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; } diff --git a/compiler/testData/codegen/boxInline/smap/defaultLambda/inlinInDefault2.kt b/compiler/testData/codegen/boxInline/smap/defaultLambda/inlinInDefault2.kt index e96f25ac1a7..cfe124f4274 100644 --- a/compiler/testData/codegen/boxInline/smap/defaultLambda/inlinInDefault2.kt +++ b/compiler/testData/codegen/boxInline/smap/defaultLambda/inlinInDefault2.kt @@ -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 \ No newline at end of file diff --git a/compiler/testData/debug/stepping/lambdaStepInline.kt b/compiler/testData/debug/stepping/lambdaStepInline.kt new file mode 100644 index 00000000000..eee97f6b5f4 --- /dev/null +++ b/compiler/testData/debug/stepping/lambdaStepInline.kt @@ -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 \ No newline at end of file diff --git a/compiler/testData/debug/stepping/lambdaStepInlineWithDefaults.kt b/compiler/testData/debug/stepping/lambdaStepInlineWithDefaults.kt new file mode 100644 index 00000000000..1fccf2d99c1 --- /dev/null +++ b/compiler/testData/debug/stepping/lambdaStepInlineWithDefaults.kt @@ -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 \ No newline at end of file diff --git a/compiler/testData/debug/stepping/voidLambdaStepInline.kt b/compiler/testData/debug/stepping/voidLambdaStepInline.kt new file mode 100644 index 00000000000..d03d8235f44 --- /dev/null +++ b/compiler/testData/debug/stepping/voidLambdaStepInline.kt @@ -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 \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/IrSteppingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/IrSteppingTestGenerated.java index 27578690b49..8e263a559b6 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/IrSteppingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/IrSteppingTestGenerated.java @@ -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"); + } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/SteppingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/SteppingTestGenerated.java index 5ada2b10831..b4f2a5bfdd2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/SteppingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/debugInformation/SteppingTestGenerated.java @@ -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"); + } }