diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index f39dde393db..c91052fe5c2 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -1886,6 +1886,10 @@ public class ExpressionCodegen extends KtVisitor impleme if (!endsWithReturn(expr)) { markLineNumber(expr, true); + if (isLambdaVoidBody(expr, returnType)) { + markLineNumber((KtFunctionLiteral) expr.getParent(), true); + } + if (isBlockedNamedFunction && !Type.VOID_TYPE.equals(expressionType(expr))) { StackValue.none().put(returnType, v); } @@ -1903,6 +1907,17 @@ public class ExpressionCodegen extends KtVisitor impleme return bodyExpression instanceof KtReturnExpression; } + private static boolean isLambdaVoidBody(KtElement bodyExpression, Type returnType) { + if (bodyExpression instanceof KtBlockExpression) { + PsiElement parent = bodyExpression.getParent(); + if (parent instanceof KtFunctionLiteral) { + return Type.VOID_TYPE.equals(returnType); + } + } + + return false; + } + @Override public StackValue visitSimpleNameExpression(@NotNull KtSimpleNameExpression expression, @NotNull StackValue receiver) { ResolvedCall resolvedCall = CallUtilKt.getResolvedCall(expression, bindingContext); diff --git a/compiler/testData/codegen/boxInline/smap/anonymous/lambda.1.kt b/compiler/testData/codegen/boxInline/smap/anonymous/lambda.1.kt index a72d33bf5b1..5f41c9798a3 100644 --- a/compiler/testData/codegen/boxInline/smap/anonymous/lambda.1.kt +++ b/compiler/testData/codegen/boxInline/smap/anonymous/lambda.1.kt @@ -42,5 +42,5 @@ fun box(): String { //Lambda_1Kt //*L //1#1,18:1 -//8#2:19 +//8#2,2:19 //*E \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/smap/anonymous/object.1.kt b/compiler/testData/codegen/boxInline/smap/anonymous/object.1.kt index 334fdcd43c4..02cc8575470 100644 --- a/compiler/testData/codegen/boxInline/smap/anonymous/object.1.kt +++ b/compiler/testData/codegen/boxInline/smap/anonymous/object.1.kt @@ -41,5 +41,5 @@ fun box(): String { //Object_1Kt //*L //1#1,21:1 -//8#2:22 +//8#2,2:22 //*E \ No newline at end of file diff --git a/compiler/testData/lineNumber/custom/functionCallWithInlinedLambdaParam.kt b/compiler/testData/lineNumber/custom/functionCallWithInlinedLambdaParam.kt index 73f223d696e..f102dd1314e 100644 --- a/compiler/testData/lineNumber/custom/functionCallWithInlinedLambdaParam.kt +++ b/compiler/testData/lineNumber/custom/functionCallWithInlinedLambdaParam.kt @@ -13,4 +13,4 @@ inline fun foo(f: () -> Unit) { f() } -// 2 12 13 3 14 6 12 13 7 14 9 12 13 14 +// 2 12 13 3 4 14 6 12 13 7 8 14 9 12 13 14 diff --git a/compiler/testData/lineNumber/custom/functionCallWithLambdaParam.kt b/compiler/testData/lineNumber/custom/functionCallWithLambdaParam.kt index 7df50dea309..392aa085d4c 100644 --- a/compiler/testData/lineNumber/custom/functionCallWithLambdaParam.kt +++ b/compiler/testData/lineNumber/custom/functionCallWithLambdaParam.kt @@ -12,4 +12,4 @@ fun foo(f: () -> Unit) { f() } -// 2 6 9 12 13 3 7 +// 2 6 9 12 13 3 4 7 8 diff --git a/idea/testData/debugger/tinyApp/outs/functionCallStoredToVariable.out b/idea/testData/debugger/tinyApp/outs/functionCallStoredToVariable.out index cf4fc12a5fd..e231002591a 100644 --- a/idea/testData/debugger/tinyApp/outs/functionCallStoredToVariable.out +++ b/idea/testData/debugger/tinyApp/outs/functionCallStoredToVariable.out @@ -11,8 +11,10 @@ functionCallStoredToVariable.kt:0 functionCallStoredToVariable.kt:43 functionCallStoredToVariable.kt:11 functionCallStoredToVariable.kt:21 +functionCallStoredToVariable.kt:22 functionCallStoredToVariable.kt:18 functionCallStoredToVariable.kt:28 +functionCallStoredToVariable.kt:29 functionCallStoredToVariable.kt:0 functionCallStoredToVariable.kt:47 functionCallStoredToVariable.kt:25 diff --git a/idea/testData/debugger/tinyApp/outs/syntheticMethods.out b/idea/testData/debugger/tinyApp/outs/syntheticMethods.out index dfe35efefcb..3f6a3f4c060 100644 --- a/idea/testData/debugger/tinyApp/outs/syntheticMethods.out +++ b/idea/testData/debugger/tinyApp/outs/syntheticMethods.out @@ -16,7 +16,7 @@ syntheticMethods.kt:23 syntheticMethods.kt:26 syntheticMethods.kt:23 syntheticMethods.kt:31 -syntheticMethods.kt:32 +syntheticMethods.kt:25 syntheticMethods.kt:28 syntheticMethods.kt:8 syntheticMethods.kt:36 @@ -25,7 +25,7 @@ syntheticMethods.kt:34 syntheticMethods.kt:37 syntheticMethods.kt:34 syntheticMethods.kt:42 -syntheticMethods.kt:43 +syntheticMethods.kt:36 syntheticMethods.kt:39 syntheticMethods.kt:9 Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' diff --git a/idea/testData/debugger/tinyApp/outs/twoLambdasOnOneLineSecond.out b/idea/testData/debugger/tinyApp/outs/twoLambdasOnOneLineSecond.out index cd4d5d9999d..cad656fdce8 100644 --- a/idea/testData/debugger/tinyApp/outs/twoLambdasOnOneLineSecond.out +++ b/idea/testData/debugger/tinyApp/outs/twoLambdasOnOneLineSecond.out @@ -1,14 +1,7 @@ -LineBreakpoint created at twoLambdasOnOneLineSecond.kt:9 +LineBreakpoint created at twoLambdasOnOneLineSecond.kt:8 lambdaOrdinal = 1 !JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !OUTPUT_PATH!;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! twoLambdasOnOneLineSecond.TwoLambdasOnOneLineSecondKt Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' -twoLambdasOnOneLineSecond.kt:9 -twoLambdasOnOneLineSecond.kt:14 -twoLambdasOnOneLineSecond.kt:9 -twoLambdasOnOneLineSecond.kt:0 -twoLambdasOnOneLineSecond.kt:14 -twoLambdasOnOneLineSecond.kt:9 -twoLambdasOnOneLineSecond.kt:14 -twoLambdasOnOneLineSecond.kt:9 +twoLambdasOnOneLineSecond.kt:8 Compile bytecode for it Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' diff --git a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/lambdas/twoLambdasOnOneLineSecond.kt b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/lambdas/twoLambdasOnOneLineSecond.kt index 60ceedc58b6..9f561bb90a8 100644 --- a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/lambdas/twoLambdasOnOneLineSecond.kt +++ b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/lambdas/twoLambdasOnOneLineSecond.kt @@ -4,8 +4,7 @@ fun main(args: Array) { val a = A() // EXPRESSION: it // RESULT: 2: I - // STEP_INTO: 7 - //Breakpoint! + //Breakpoint! (lambdaOrdinal = 1) a.foo(1) { a }.foo(2) { a } } diff --git a/idea/testData/debugger/tinyApp/src/stepping/custom/functionCallStoredToVariable.kt b/idea/testData/debugger/tinyApp/src/stepping/custom/functionCallStoredToVariable.kt index 510e3d07bc5..c38b6cca015 100644 --- a/idea/testData/debugger/tinyApp/src/stepping/custom/functionCallStoredToVariable.kt +++ b/idea/testData/debugger/tinyApp/src/stepping/custom/functionCallStoredToVariable.kt @@ -16,14 +16,14 @@ fun main(args: Array) { // RESUME: 1 val c = inlineFunVoid { - // STEP_OVER: 1 + // STEP_OVER: 2 //Breakpoint! val aa = 1 } // RESUME: 1 val d = simpleFunVoid { - // STEP_OVER: 3 + // STEP_OVER: 4 //Breakpoint! val aa = 1 } diff --git a/idea/testData/debugger/tinyApp/src/stepping/stepInto/syntheticMethods.kt b/idea/testData/debugger/tinyApp/src/stepping/stepInto/syntheticMethods.kt index da9c033db06..8a91d838fda 100644 --- a/idea/testData/debugger/tinyApp/src/stepping/stepInto/syntheticMethods.kt +++ b/idea/testData/debugger/tinyApp/src/stepping/stepInto/syntheticMethods.kt @@ -23,23 +23,23 @@ class Derived: Base() { class A { fun test() { lambda { - val a = 1 + 1 } } - fun lambda(f: () -> Unit) { - f() + fun lambda(f: () -> Int): Int { + return f() } companion object { fun test() { lambda { - val a = 1 + 1 } } - fun lambda(f: () -> Unit) { - f() + fun lambda(f: () -> Int): Int { + return f() } } } diff --git a/idea/testData/debugger/tinyApp/src/stepping/stepOut/stepOutSeveralInlineArgumentDeepest.kt b/idea/testData/debugger/tinyApp/src/stepping/stepOut/stepOutSeveralInlineArgumentDeepest.kt index c6e40a1fa71..5d2c5b2c833 100644 --- a/idea/testData/debugger/tinyApp/src/stepping/stepOut/stepOutSeveralInlineArgumentDeepest.kt +++ b/idea/testData/debugger/tinyApp/src/stepping/stepOut/stepOutSeveralInlineArgumentDeepest.kt @@ -8,7 +8,7 @@ fun main(args: Array) { test(3) } -inline fun f1(f: () -> Unit) { +inline fun f1(f: () -> Int) { val a = 1 f2 { f() @@ -16,10 +16,10 @@ inline fun f1(f: () -> Unit) { val b = 2 } -inline fun f2(f: () -> Unit) { +inline fun f2(f: () -> Int): Int { val a = 1 f() - val b = 2 + return 2 } fun test(i: Int) = 1