Supported calls of SAM adapters for constructors.
This commit is contained in:
@@ -1891,17 +1891,17 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private SimpleFunctionDescriptor getOriginalIfSamAdapter(@NotNull CallableDescriptor fun) {
|
private FunctionDescriptor getOriginalIfSamAdapter(@NotNull CallableDescriptor fun) {
|
||||||
if (!(fun instanceof SimpleFunctionDescriptor)) {
|
if (!(fun instanceof FunctionDescriptor)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
SimpleFunctionDescriptor original = ((SimpleFunctionDescriptor) fun).getOriginal();
|
FunctionDescriptor original = ((FunctionDescriptor) fun).getOriginal();
|
||||||
if (original.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) {
|
if (original.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) {
|
||||||
return (SimpleFunctionDescriptor) bindingContext.get(SAM_ADAPTER_FUNCTION_TO_ORIGINAL, original); // TODO support constructor
|
return bindingContext.get(SAM_ADAPTER_FUNCTION_TO_ORIGINAL, original);
|
||||||
}
|
}
|
||||||
if (original.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
if (original.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||||
for (FunctionDescriptor overridden : original.getOverriddenDescriptors()) {
|
for (FunctionDescriptor overridden : original.getOverriddenDescriptors()) {
|
||||||
SimpleFunctionDescriptor originalIfSamAdapter = getOriginalIfSamAdapter(overridden);
|
FunctionDescriptor originalIfSamAdapter = getOriginalIfSamAdapter(overridden);
|
||||||
if (originalIfSamAdapter != null) {
|
if (originalIfSamAdapter != null) {
|
||||||
return originalIfSamAdapter;
|
return originalIfSamAdapter;
|
||||||
}
|
}
|
||||||
@@ -2059,7 +2059,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
return typeMapper.mapToFunctionInvokeCallableMethod(createInvoke(fd));
|
return typeMapper.mapToFunctionInvokeCallableMethod(createInvoke(fd));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SimpleFunctionDescriptor originalOfSamAdapter = getOriginalIfSamAdapter(fd);
|
SimpleFunctionDescriptor originalOfSamAdapter = (SimpleFunctionDescriptor) getOriginalIfSamAdapter(fd);
|
||||||
return typeMapper.mapToCallableMethod(originalOfSamAdapter != null ? originalOfSamAdapter : fd, superCall,
|
return typeMapper.mapToCallableMethod(originalOfSamAdapter != null ? originalOfSamAdapter : fd, superCall,
|
||||||
isCallInsideSameClassAsDeclared(fd, context),
|
isCallInsideSameClassAsDeclared(fd, context),
|
||||||
isCallInsideSameModuleAsDeclared(fd, context),
|
isCallInsideSameModuleAsDeclared(fd, context),
|
||||||
@@ -2293,7 +2293,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
int mask = 0;
|
int mask = 0;
|
||||||
|
|
||||||
SimpleFunctionDescriptor originalOfSamAdapter = getOriginalIfSamAdapter(fd);
|
FunctionDescriptor originalOfSamAdapter = getOriginalIfSamAdapter(fd);
|
||||||
|
|
||||||
for (ValueParameterDescriptor valueParameter : fd.getValueParameters()) {
|
for (ValueParameterDescriptor valueParameter : fd.getValueParameters()) {
|
||||||
ResolvedValueArgument resolvedValueArgument = valueArguments.get(valueParameter.getIndex());
|
ResolvedValueArgument resolvedValueArgument = valueArguments.get(valueParameter.getIndex());
|
||||||
@@ -3263,7 +3263,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
//See StackValue.receiver for more info
|
//See StackValue.receiver for more info
|
||||||
pushClosureOnStack(closure, resolvedCall.getThisObject().exists() || resolvedCall.getReceiverArgument().exists());
|
pushClosureOnStack(closure, resolvedCall.getThisObject().exists() || resolvedCall.getReceiverArgument().exists());
|
||||||
|
|
||||||
CallableMethod method = typeMapper.mapToCallableMethod(constructorDescriptor);
|
ConstructorDescriptor originalOfSamAdapter = (ConstructorDescriptor) getOriginalIfSamAdapter(constructorDescriptor);
|
||||||
|
CallableMethod method = typeMapper.mapToCallableMethod(originalOfSamAdapter == null ? constructorDescriptor : originalOfSamAdapter);
|
||||||
invokeMethodWithArguments(method, resolvedCall, null, StackValue.none());
|
invokeMethodWithArguments(method, resolvedCall, null, StackValue.none());
|
||||||
|
|
||||||
return StackValue.onStack(type);
|
return StackValue.onStack(type);
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
class JavaClass {
|
||||||
|
private Runnable r;
|
||||||
|
|
||||||
|
public JavaClass(Runnable r) {
|
||||||
|
this.r = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
r.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun box(): String {
|
||||||
|
var v = "FAIL"
|
||||||
|
JavaClass { v = "OK" }.run()
|
||||||
|
return v
|
||||||
|
}
|
||||||
+5
@@ -145,6 +145,11 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
|
|||||||
doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/comparator.kt");
|
doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/comparator.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("constructor.kt")
|
||||||
|
public void testConstructor() throws Exception {
|
||||||
|
doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/constructor.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("fileFilter.kt")
|
@TestMetadata("fileFilter.kt")
|
||||||
public void testFileFilter() throws Exception {
|
public void testFileFilter() throws Exception {
|
||||||
doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/fileFilter.kt");
|
doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/fileFilter.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user