Write lineNumber for function literal with void return value

#KT-9865 Fixed
This commit is contained in:
Natalia Ukhorskaya
2015-11-24 12:21:29 +03:00
parent 4a2e4312ea
commit cb80a3e83a
12 changed files with 37 additions and 28 deletions
@@ -1886,6 +1886,10 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> 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<StackValue, StackValue> 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);
@@ -42,5 +42,5 @@ fun box(): String {
//Lambda_1Kt
//*L
//1#1,18:1
//8#2:19
//8#2,2:19
//*E
@@ -41,5 +41,5 @@ fun box(): String {
//Object_1Kt
//*L
//1#1,21:1
//8#2:22
//8#2,2:22
//*E
@@ -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
@@ -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
@@ -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
+2 -2
View File
@@ -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'
@@ -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'
@@ -4,8 +4,7 @@ fun main(args: Array<String>) {
val a = A()
// EXPRESSION: it
// RESULT: 2: I
// STEP_INTO: 7
//Breakpoint!
//Breakpoint! (lambdaOrdinal = 1)
a.foo(1) { a }.foo(2) { a }
}
@@ -16,14 +16,14 @@ fun main(args: Array<String>) {
// 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
}
@@ -23,23 +23,23 @@ class Derived: Base<String>() {
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()
}
}
}
@@ -8,7 +8,7 @@ fun main(args: Array<String>) {
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