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