KT-3538: Super call to trait implemetation invokes method from base class

This commit is contained in:
Mikhael Bogdanov
2013-04-24 13:18:40 +04:00
parent aa2db75266
commit b6fc0c5c13
3 changed files with 39 additions and 4 deletions
@@ -508,9 +508,11 @@ public class JetTypeMapper extends BindingTraceAware {
boolean isInterface = originalIsInterface && currentIsInterface;
Type type = mapType(receiver.getDefaultType(), JetTypeMapperMode.TYPE_PARAMETER);
owner = JvmClassName.byType(type);
ownerForDefaultParam = JvmClassName.byType(mapType(declarationOwner.getDefaultType(), JetTypeMapperMode.TYPE_PARAMETER));
ClassDescriptor declarationOwnerForDefault = (ClassDescriptor) findBaseDeclaration(functionDescriptor).getContainingDeclaration();
ownerForDefaultParam = JvmClassName.byType(mapType(declarationOwnerForDefault.getDefaultType(), JetTypeMapperMode.TYPE_PARAMETER));
ownerForDefaultImpl = JvmClassName.byInternalName(
ownerForDefaultParam.getInternalName() + (originalIsInterface ? JvmAbi.TRAIT_IMPL_SUFFIX : ""));
ownerForDefaultParam.getInternalName() + (isInterface(declarationOwnerForDefault) ? JvmAbi.TRAIT_IMPL_SUFFIX : ""));
if (isInterface) {
invokeOpcode = superCall ? INVOKESTATIC : INVOKEINTERFACE;
}
@@ -557,13 +559,20 @@ public class JetTypeMapper extends BindingTraceAware {
@NotNull
private static FunctionDescriptor findAnyDeclaration(@NotNull FunctionDescriptor function) {
//if (function.getKind() == CallableMemberDescriptor.Kind.DECLARATION) {
if (function.getKind() == CallableMemberDescriptor.Kind.DECLARATION) {
return function;
}
return findBaseDeclaration(function);
}
@NotNull
private static FunctionDescriptor findBaseDeclaration(@NotNull FunctionDescriptor function) {
if (function.getOverriddenDescriptors().isEmpty()) {
return function;
}
else {
// TODO: prefer class to interface
return findAnyDeclaration(function.getOverriddenDescriptors().iterator().next());
return findBaseDeclaration(function.getOverriddenDescriptors().iterator().next());
}
}
@@ -0,0 +1,21 @@
open class Base {
open fun sayHello(): String {
return "O"
}
}
trait Trait: Base {
override fun sayHello(): String {
return "K"
}
}
class Derived(): Base(), Trait {
override fun sayHello(): String {
return super<Base>.sayHello() + super<Trait>.sayHello()
}
}
fun box(): String {
return Derived().sayHello()
}
@@ -3616,6 +3616,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/super/kt3492TraitProperty.kt");
}
@TestMetadata("kt3538.kt")
public void testKt3538() throws Exception {
doTest("compiler/testData/codegen/box/super/kt3538.kt");
}
@TestMetadata("multipleSuperTraits.kt")
public void testMultipleSuperTraits() throws Exception {
doTest("compiler/testData/codegen/box/super/multipleSuperTraits.kt");