From d282f14eac2ff735eb4b398ffac4b6350f809ff4 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Sat, 15 Jul 2017 16:21:51 +0300 Subject: [PATCH] Don't add double linenumber when return expression is absent (KT-18949) #KT-18949 Fixed --- .../kotlin/codegen/ExpressionCodegen.java | 5 +++-- .../inTheEndOfLambdaArgumentOfInlineCall.kt | 19 +++++++++++++++++++ .../codegen/LineNumberTestGenerated.java | 6 ++++++ .../custom/stepIntoStdlibInlineFun2step.kt | 2 +- ...stStatementInInlineFunctionArgumentDex.out | 3 ++- 5 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/lineNumber/custom/inTheEndOfLambdaArgumentOfInlineCall.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 91faa53d558..daf403062c6 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -1613,11 +1613,12 @@ public class ExpressionCodegen extends KtVisitor impleme // If it does not end with return we should return something // because if we don't there can be VerifyError (specific cases with Nothing-typed expressions) if (!endsWithReturn(expr)) { - markLineNumber(expr, true); - if (isLambdaVoidBody(expr, typeForExpression)) { markLineNumber((KtFunctionLiteral) expr.getParent(), true); } + else { + markLineNumber(expr, true); + } if (typeForExpression.getSort() == Type.VOID) { StackValue.none().put(returnType, v); diff --git a/compiler/testData/lineNumber/custom/inTheEndOfLambdaArgumentOfInlineCall.kt b/compiler/testData/lineNumber/custom/inTheEndOfLambdaArgumentOfInlineCall.kt new file mode 100644 index 00000000000..429c2b0484b --- /dev/null +++ b/compiler/testData/lineNumber/custom/inTheEndOfLambdaArgumentOfInlineCall.kt @@ -0,0 +1,19 @@ +fun foo() { + bar { + nop() + baz() + } +} + +inline fun bar(f: () -> Unit) { + nop() + f() +} + +inline fun baz() { + nop() +} + +fun nop() {} + +// 2 20 21 3 4 25 26 5 27 6 9 10 11 14 15 17 \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LineNumberTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LineNumberTestGenerated.java index 72834b5d837..63737eea752 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LineNumberTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LineNumberTestGenerated.java @@ -209,6 +209,12 @@ public class LineNumberTestGenerated extends AbstractLineNumberTest { doTestCustom(fileName); } + @TestMetadata("inTheEndOfLambdaArgumentOfInlineCall.kt") + public void testInTheEndOfLambdaArgumentOfInlineCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/lineNumber/custom/inTheEndOfLambdaArgumentOfInlineCall.kt"); + doTestCustom(fileName); + } + @TestMetadata("multilineFunctionCall.kt") public void testMultilineFunctionCall() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/lineNumber/custom/multilineFunctionCall.kt"); diff --git a/idea/testData/debugger/tinyApp/src/stepping/custom/stepIntoStdlibInlineFun2step.kt b/idea/testData/debugger/tinyApp/src/stepping/custom/stepIntoStdlibInlineFun2step.kt index 6dd7372505e..6ea5ada7811 100644 --- a/idea/testData/debugger/tinyApp/src/stepping/custom/stepIntoStdlibInlineFun2step.kt +++ b/idea/testData/debugger/tinyApp/src/stepping/custom/stepIntoStdlibInlineFun2step.kt @@ -5,4 +5,4 @@ fun main(args: Array) { } // ADDITIONAL_BREAKPOINT: functionInLibrary.kt:public inline fun simpleFun() -// STEP_INTO: 4 \ No newline at end of file +// STEP_INTO: 5 \ No newline at end of file diff --git a/idea/testData/debugger/tinyApp/src/stepping/stepOver/soInlineCallInLastStatementInInlineFunctionArgumentDex.out b/idea/testData/debugger/tinyApp/src/stepping/stepOver/soInlineCallInLastStatementInInlineFunctionArgumentDex.out index 067c44dc138..cead4959e33 100644 --- a/idea/testData/debugger/tinyApp/src/stepping/stepOver/soInlineCallInLastStatementInInlineFunctionArgumentDex.out +++ b/idea/testData/debugger/tinyApp/src/stepping/stepOver/soInlineCallInLastStatementInInlineFunctionArgumentDex.out @@ -2,7 +2,8 @@ LineBreakpoint created at soInlineCallInLastStatementInInlineFunctionArgumentDex Run Java Connected to the target VM soInlineCallInLastStatementInInlineFunctionArgumentDex.kt:7 -soInlineCallInLastStatementInInlineFunctionArgumentDex.kt:7 +soInlineCallInLastStatementInInlineFunctionArgumentDex.kt:8 +soInlineCallInLastStatementInInlineFunctionArgumentDex.kt:14 soInlineCallInLastStatementInInlineFunctionArgumentDex.kt:9 Disconnected from the target VM