do not generate delegates when the class already has such method either declared or delegated (report an ambiguity in this case)
Merge conflict resolved by committer
This commit is contained in:
committed by
Andrey Breslav
parent
10bdc02409
commit
1061e1ef69
@@ -32,6 +32,8 @@ import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.MANY_IMPL_MEMBER_NOT_IMPLEMENTED;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
@@ -60,7 +62,18 @@ public class DelegationResolver {
|
||||
});
|
||||
|
||||
Collection<CallableMemberDescriptor> generatedDescriptors = generateDelegatedMembers(classDescriptor, descriptorsToDelegate);
|
||||
outer:
|
||||
for (CallableMemberDescriptor descriptor : generatedDescriptors) {
|
||||
for (CallableMemberDescriptor existingDescriptor : classDescriptor.getAllCallableMembers()) {
|
||||
if (OverridingUtil.isOverridableBy(existingDescriptor, descriptor).getResult() == OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE) {
|
||||
if (existingDescriptor.getKind() == CallableMemberDescriptor.Kind.DELEGATION) {
|
||||
//trying to delegate to many traits with the same methods
|
||||
trace.report(MANY_IMPL_MEMBER_NOT_IMPLEMENTED.on(jetClass.getNameIdentifier(), jetClass, existingDescriptor));
|
||||
}
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
|
||||
if (descriptor instanceof PropertyDescriptor) {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||
classDescriptor.getBuilder().addPropertyDescriptor(propertyDescriptor);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
trait One {
|
||||
public open fun foo() : Int
|
||||
public open fun faz() : Int = 10
|
||||
}
|
||||
trait Two {
|
||||
public open fun foo() : Int
|
||||
public open fun quux() : Int = 100
|
||||
}
|
||||
|
||||
class OneImpl : One {
|
||||
public override fun foo() = 1
|
||||
}
|
||||
class TwoImpl : Two {
|
||||
public override fun foo() = 2
|
||||
}
|
||||
|
||||
class Test2(a : One, b : Two) : Two by b, One by a {
|
||||
public override fun foo() = 0
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
var t2 = Test2(OneImpl(), TwoImpl())
|
||||
if (t2.foo() != 0)
|
||||
return "Fail #1"
|
||||
if (t2.faz() != 10)
|
||||
return "Fail #2"
|
||||
if (t2.quux() != 100)
|
||||
return "Fail #3"
|
||||
if (t2 !is One)
|
||||
return "Fail #4"
|
||||
if (t2 !is Two)
|
||||
return "Fail #5"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
trait One {
|
||||
public open fun foo() : Int
|
||||
private fun boo() = 10
|
||||
}
|
||||
trait Two {
|
||||
public open fun foo() : Int
|
||||
}
|
||||
|
||||
trait OneImpl : One {
|
||||
public override fun foo() = 1
|
||||
}
|
||||
trait TwoImpl : Two {
|
||||
public override fun foo() = 2
|
||||
}
|
||||
|
||||
class <!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>Test1<!>() : TwoImpl, OneImpl {}
|
||||
class Test2(a : One) : One by a, Two {}
|
||||
class <!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>Test3<!>(a : One, b : Two) : Two by b, One by a {}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -68,6 +68,11 @@ public class ClassGenTest extends CodegenTestCase {
|
||||
blackBoxFile("classes/delegation2.kt");
|
||||
}
|
||||
|
||||
public void testInheritanceAndDelegation3() throws Exception {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
blackBoxFile("classes/delegation3.kt");
|
||||
}
|
||||
|
||||
public void testFunDelegation() throws Exception {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
blackBoxFile("classes/funDelegation.jet");
|
||||
|
||||
Reference in New Issue
Block a user