提交 90038fda 编写于 作者: M Maxim Shafirov

Closure and boxing return value

上级 3619e411
......@@ -104,6 +104,7 @@ public class ClosureCodegen {
private void generateBridge(String className, FunctionDescriptor funDescriptor, ClassVisitor cv) {
final Method bridge = erasedInvokeSignature(funDescriptor);
final Method delegate = invokeSignature(funDescriptor);
final MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "invoke", bridge.getDescriptor(), typeMapper.genericSignature(funDescriptor), new String[0]);
mv.visitCode();
......@@ -120,7 +121,9 @@ public class ClosureCodegen {
count++;
}
iv.invokespecial(className, "invoke", invokeSignature(funDescriptor).getDescriptor());
iv.invokespecial(className, "invoke", delegate.getDescriptor());
StackValue.onStack(delegate.getReturnType()).put(JetTypeMapper.TYPE_OBJECT, iv);
iv.areturn(JetTypeMapper.TYPE_OBJECT);
mv.visitMaxs(0, 0);
......
......@@ -140,6 +140,9 @@ public abstract class StackValue {
box(this.type, type, v);
}
else if (this.type.getSort() == Type.OBJECT && type.getSort() <= Type.DOUBLE) {
if (this.type.equals(JetTypeMapper.TYPE_OBJECT)) {
v.checkcast(Type.getObjectType("java/lang/Number"));
}
unbox(type, v);
}
else {
......
fun box() : String {
return if (int_invoker( { 7 } ) == 7) "OK" else "fail"
}
fun int_invoker(gen : {() : Int}) : Int {
return gen()
}
......@@ -7,4 +7,8 @@ public class ClosuresGenTest extends CodegenTestCase {
public void testSimplestClosure() throws Exception {
blackBoxFile("classes/simplestClosure.jet");
}
public void testSimplestClosureAndBoxing() throws Exception {
blackBoxFile("classes/simplestClosureAndBoxing.jet");
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册