Fix for KT-14243: Wrong invocation descriptor on calling implicitly generated implementation in class

#KT-14243 Fixed
This commit is contained in:
Michael Bogdanov
2016-10-09 12:27:04 +03:00
parent ce0d81f670
commit 5bd045c79c
11 changed files with 242 additions and 1 deletions
@@ -591,6 +591,37 @@ public class KotlinTypeMapper {
return Variance.OUT_VARIANCE;
}
//NB: similar platform agnostic code in DescriptorUtils.unwrapFakeOverride
private FunctionDescriptor findSuperDeclaration(@NotNull FunctionDescriptor descriptor, boolean isSuperCall) {
while (descriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
Collection<? extends FunctionDescriptor> overridden = descriptor.getOverriddenDescriptors();
if (overridden.isEmpty()) {
throw new IllegalStateException("Fake override should have at least one overridden descriptor: " + descriptor);
}
FunctionDescriptor classCallable = null;
for (FunctionDescriptor overriddenFunction : overridden) {
if (!isInterface(overriddenFunction.getContainingDeclaration())) {
classCallable = overriddenFunction;
break;
}
}
if (classCallable != null) {
//prefer class callable cause of else branch
descriptor = classCallable;
continue;
}
else if (isSuperCall && !isJvm8Target && !isInterface(descriptor.getContainingDeclaration())) {
//Don't unwrap fake overrides from class to interface cause substituted override would be implicitly generated for target 1.6
return descriptor;
}
descriptor = overridden.iterator().next();
}
return descriptor;
}
@NotNull
public CallableMethod mapToCallableMethod(@NotNull FunctionDescriptor descriptor, boolean superCall) {
if (descriptor instanceof ConstructorDescriptor) {
@@ -609,7 +640,7 @@ public class KotlinTypeMapper {
DeclarationDescriptor functionParent = descriptor.getOriginal().getContainingDeclaration();
FunctionDescriptor functionDescriptor = unwrapFakeOverride(descriptor.getOriginal());
FunctionDescriptor functionDescriptor = findSuperDeclaration(descriptor.getOriginal(), superCall);
JvmMethodSignature signature;
Type owner;