Handling null correctly when wrapping function in SAM wrapper

This commit is contained in:
Evgeny Gerashchenko
2013-06-27 20:37:27 +04:00
parent c6f6e6c756
commit 3e70661a6d
4 changed files with 29 additions and 0 deletions
@@ -1928,7 +1928,22 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
Type functionType = typeMapper.mapType(samInterface.getFunctionTypeForSamInterface());
expression.accept(visitor, StackValue.none()).put(functionType, v);
Label ifNonNull = new Label();
Label afterAll = new Label();
v.dup();
v.ifnonnull(ifNonNull);
// if null: pop function value and wrapper objects, put null
v.pop();
v.pop2();
v.aconst(null);
v.goTo(afterAll);
v.mark(ifNonNull);
v.invokespecial(className.getInternalName(), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, functionType));
v.mark(afterAll);
return StackValue.onStack(className.getAsmType());
}
}