Handling null correctly when wrapping function in SAM wrapper
This commit is contained in:
@@ -1928,7 +1928,22 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
Type functionType = typeMapper.mapType(samInterface.getFunctionTypeForSamInterface());
|
Type functionType = typeMapper.mapType(samInterface.getFunctionTypeForSamInterface());
|
||||||
expression.accept(visitor, StackValue.none()).put(functionType, v);
|
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.invokespecial(className.getInternalName(), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, functionType));
|
||||||
|
|
||||||
|
v.mark(afterAll);
|
||||||
return StackValue.onStack(className.getAsmType());
|
return StackValue.onStack(className.getAsmType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class JavaClass {
|
||||||
|
public static String run(Runnable r) {
|
||||||
|
return r == null ? "OK" : "FAIL";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun box(): String {
|
||||||
|
val f: (() -> Unit)? = null
|
||||||
|
return JavaClass.run(f)!!
|
||||||
|
}
|
||||||
+5
@@ -191,6 +191,11 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
|
|||||||
doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/nonLiteralInConstructor.kt");
|
doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/nonLiteralInConstructor.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nonLiteralNull.kt")
|
||||||
|
public void testNonLiteralNull() throws Exception {
|
||||||
|
doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/nonLiteralNull.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nonLiteralRunnable.kt")
|
@TestMetadata("nonLiteralRunnable.kt")
|
||||||
public void testNonLiteralRunnable() throws Exception {
|
public void testNonLiteralRunnable() throws Exception {
|
||||||
doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/nonLiteralRunnable.kt");
|
doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/nonLiteralRunnable.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user