Fixed calling inherited SAM adapter.
This commit is contained in:
@@ -1806,7 +1806,18 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
SimpleFunctionDescriptor original = ((SimpleFunctionDescriptor) fun).getOriginal();
|
SimpleFunctionDescriptor original = ((SimpleFunctionDescriptor) fun).getOriginal();
|
||||||
return bindingContext.get(SAM_ADAPTER_FUNCTION_TO_ORIGINAL, original);
|
if (original.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) {
|
||||||
|
return bindingContext.get(SAM_ADAPTER_FUNCTION_TO_ORIGINAL, original);
|
||||||
|
}
|
||||||
|
if (original.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||||
|
for (FunctionDescriptor overridden : original.getOverriddenDescriptors()) {
|
||||||
|
SimpleFunctionDescriptor originalIfSamAdapter = getOriginalIfSamAdapter(overridden);
|
||||||
|
if (originalIfSamAdapter != null) {
|
||||||
|
return originalIfSamAdapter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private StackValue invokeSamConstructor(
|
private StackValue invokeSamConstructor(
|
||||||
|
|||||||
+16
-2
@@ -106,8 +106,22 @@ public class TaskPrioritizer {
|
|||||||
|
|
||||||
private boolean isSynthesized(ResolutionCandidate<D> call) {
|
private boolean isSynthesized(ResolutionCandidate<D> call) {
|
||||||
D descriptor = call.getDescriptor();
|
D descriptor = call.getDescriptor();
|
||||||
return descriptor instanceof CallableMemberDescriptor &&
|
return descriptor instanceof CallableMemberDescriptor && isOrOverridesSynthesized((CallableMemberDescriptor) descriptor);
|
||||||
((CallableMemberDescriptor) descriptor).getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED;
|
}
|
||||||
|
|
||||||
|
private boolean isOrOverridesSynthesized(CallableMemberDescriptor descriptor) {
|
||||||
|
if (descriptor.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (descriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||||
|
for (CallableMemberDescriptor overridden : descriptor.getOverriddenDescriptors()) {
|
||||||
|
if (!isOrOverridesSynthesized(overridden)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
class Super {
|
||||||
|
void safeInvoke(Runnable r) {
|
||||||
|
if (r != null) r.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Sub extends Super {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun box(): String {
|
||||||
|
var r = "FAIL"
|
||||||
|
val sub = Sub()
|
||||||
|
sub.safeInvoke(null)
|
||||||
|
sub.safeInvoke { r = "OK" }
|
||||||
|
return r
|
||||||
|
}
|
||||||
+5
@@ -135,6 +135,11 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
|
|||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/boxWithJava/samAdapters"), Pattern.compile("^(.+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/boxWithJava/samAdapters"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("cantCallInherited.kt")
|
||||||
|
public void testCantCallInherited() throws Exception {
|
||||||
|
doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/cantCallInherited.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("comparator.kt")
|
@TestMetadata("comparator.kt")
|
||||||
public void testComparator() throws Exception {
|
public void testComparator() throws Exception {
|
||||||
doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/comparator.kt");
|
doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/comparator.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user