Choosing most specific super member when building fake override. Previously, random one was chosen.

This commit is contained in:
Evgeny Gerashchenko
2013-07-12 18:35:34 +04:00
parent b6e7dcbb02
commit 13849f6b6e
20 changed files with 306 additions and 12 deletions
@@ -243,12 +243,45 @@ public class OverrideResolver {
while (!fromSuperQueue.isEmpty()) {
CallableMemberDescriptor notOverriddenFromSuper = VisibilityUtil.findMemberWithMaxVisibility(fromSuperQueue);
Collection<CallableMemberDescriptor> overridables = extractMembersOverridableBy(notOverriddenFromSuper, fromSuperQueue, sink);
createAndBindFakeOverride(notOverriddenFromSuper, overridables, current, sink);
createAndBindFakeOverride(overridables, current, sink);
}
}
private static boolean isMoreSpecific(@NotNull CallableMemberDescriptor a, @NotNull CallableMemberDescriptor b) {
if (a instanceof SimpleFunctionDescriptor) {
assert b instanceof SimpleFunctionDescriptor : "b is " + b.getClass();
JetType aReturnType = a.getReturnType();
assert aReturnType != null;
JetType bReturnType = b.getReturnType();
assert bReturnType != null;
return JetTypeChecker.INSTANCE.isSubtypeOf(aReturnType, bReturnType);
}
if (a instanceof PropertyDescriptor) {
assert b instanceof PropertyDescriptor : "b is " + b.getClass();
if (((PropertyDescriptor) a).isVar() || ((PropertyDescriptor) b).isVar()) {
return ((PropertyDescriptor) a).isVar();
}
// both vals
return JetTypeChecker.INSTANCE.isSubtypeOf(((PropertyDescriptor) a).getType(), ((PropertyDescriptor) b).getType());
}
throw new IllegalArgumentException("Unexpected callable: " + a.getClass());
}
private static CallableMemberDescriptor selectMostSpecificMemberFromSuper(@NotNull Collection<CallableMemberDescriptor> overridables) {
CallableMemberDescriptor result = null;
for (CallableMemberDescriptor overridable : overridables) {
if (result == null || isMoreSpecific(overridable, result)) {
result = overridable;
}
}
return result;
}
private static void createAndBindFakeOverride(
@NotNull CallableMemberDescriptor notOverriddenFromSuper,
@NotNull Collection<CallableMemberDescriptor> overridables,
@NotNull ClassDescriptor current,
@NotNull DescriptorSink sink
@@ -258,8 +291,9 @@ public class OverrideResolver {
boolean allInvisible = visibleOverridables.isEmpty();
Collection<CallableMemberDescriptor> effectiveOverridden = allInvisible ? overridables : visibleOverridables;
Visibility visibility = allInvisible ? Visibilities.INVISIBLE_FAKE : Visibilities.INHERITED;
CallableMemberDescriptor mostSpecific = selectMostSpecificMemberFromSuper(effectiveOverridden);
CallableMemberDescriptor fakeOverride =
notOverriddenFromSuper.copy(current, modality, visibility, CallableMemberDescriptor.Kind.FAKE_OVERRIDE, false);
mostSpecific.copy(current, modality, visibility, CallableMemberDescriptor.Kind.FAKE_OVERRIDE, false);
for (CallableMemberDescriptor descriptor : effectiveOverridden) {
OverridingUtil.bindOverride(fakeOverride, descriptor);
}
+1 -1
View File
@@ -1323,7 +1323,7 @@ public trait MutableList</*0*/ E> : jet.List<E>, jet.MutableCollection<E> {
public abstract override /*2*/ /*fake_override*/ fun hashCode(): jet.Int
public abstract override /*1*/ /*fake_override*/ fun indexOf(/*0*/ o: jet.Any?): jet.Int
public abstract override /*2*/ /*fake_override*/ fun isEmpty(): jet.Boolean
public abstract override /*2*/ /*fake_override*/ fun iterator(): jet.Iterator<E>
public abstract override /*2*/ /*fake_override*/ fun iterator(): jet.MutableIterator<E>
public abstract override /*1*/ /*fake_override*/ fun lastIndexOf(/*0*/ o: jet.Any?): jet.Int
public abstract override /*1*/ fun listIterator(): jet.MutableListIterator<E>
public abstract override /*1*/ fun listIterator(/*0*/ index: jet.Int): jet.MutableListIterator<E>
@@ -3,7 +3,7 @@ package test
public trait SamSubinterfaceOfTwo : java.lang.Object {
public trait Sub : test.SamSubinterfaceOfTwo.Super1, test.SamSubinterfaceOfTwo.Super2<jet.String> {
public abstract override /*2*/ /*fake_override*/ fun f(): jet.CharSequence?
public abstract override /*2*/ /*fake_override*/ fun f(): jet.String?
}
public trait Super1 : java.lang.Object {
@@ -0,0 +1,16 @@
package test;
public final class InheritMethodsDifferentReturnTypes {
public interface Super1 {
CharSequence foo();
String bar();
}
public interface Super2 {
String foo();
CharSequence bar();
}
public interface Sub extends Super1, Super2 {
}
}
@@ -0,0 +1,16 @@
package test
public class InheritMethodsDifferentReturnTypes: Object() {
public trait Super1: Object {
public fun foo(): CharSequence?
public fun bar(): String?
}
public trait Super2: Object {
public fun foo(): String?
public fun bar(): CharSequence?
}
public trait Sub: Super1, Super2 {
}
}
@@ -0,0 +1,20 @@
package test
public final class InheritMethodsDifferentReturnTypes : java.lang.Object {
public constructor InheritMethodsDifferentReturnTypes()
public trait Sub : test.InheritMethodsDifferentReturnTypes.Super1, test.InheritMethodsDifferentReturnTypes.Super2 {
public abstract override /*2*/ /*fake_override*/ fun bar(): jet.String?
public abstract override /*2*/ /*fake_override*/ fun foo(): jet.String?
}
public trait Super1 : java.lang.Object {
public abstract fun bar(): jet.String?
public abstract fun foo(): jet.CharSequence?
}
public trait Super2 : java.lang.Object {
public abstract fun bar(): jet.CharSequence?
public abstract fun foo(): jet.String?
}
}
@@ -0,0 +1,16 @@
package test;
public final class InheritMethodsDifferentReturnTypesGeneric {
public interface Super1<F, B> {
F foo();
B bar();
}
public interface Super2<FF, BB> {
FF foo();
BB bar();
}
public interface Sub extends Super1<String, CharSequence>, Super2<CharSequence, String> {
}
}
@@ -0,0 +1,16 @@
package test
public class InheritMethodsDifferentReturnTypesGeneric: Object() {
public trait Super1<F, B>: Object {
public fun foo(): F?
public fun bar(): B?
}
public trait Super2<FF, BB>: Object {
public fun foo(): FF?
public fun bar(): BB?
}
public trait Sub: Super1<String, CharSequence>, Super2<CharSequence, String> {
}
}
@@ -0,0 +1,20 @@
package test
public final class InheritMethodsDifferentReturnTypesGeneric : java.lang.Object {
public constructor InheritMethodsDifferentReturnTypesGeneric()
public trait Sub : test.InheritMethodsDifferentReturnTypesGeneric.Super1<jet.String, jet.CharSequence>, test.InheritMethodsDifferentReturnTypesGeneric.Super2<jet.CharSequence, jet.String> {
public abstract override /*2*/ /*fake_override*/ fun bar(): jet.String?
public abstract override /*2*/ /*fake_override*/ fun foo(): jet.String?
}
public trait Super1</*0*/ F, /*1*/ B> : java.lang.Object {
public abstract fun bar(): B?
public abstract fun foo(): F?
}
public trait Super2</*0*/ FF, /*1*/ BB> : java.lang.Object {
public abstract fun bar(): BB?
public abstract fun foo(): FF?
}
}
@@ -23,7 +23,7 @@ public trait HalfSubstitutedTypeParameters : java.lang.Object {
public abstract override /*1*/ /*fake_override*/ fun get(/*0*/ index: jet.Int): E
public abstract override /*1*/ /*fake_override*/ fun indexOf(/*0*/ o: jet.Any?): jet.Int
public abstract override /*1*/ /*fake_override*/ fun isEmpty(): jet.Boolean
public abstract override /*1*/ /*fake_override*/ fun iterator(): jet.Iterator<E>
public abstract override /*1*/ /*fake_override*/ fun iterator(): jet.MutableIterator<E>
public abstract override /*1*/ /*fake_override*/ fun lastIndexOf(/*0*/ o: jet.Any?): jet.Int
public abstract override /*1*/ /*fake_override*/ fun listIterator(): jet.MutableListIterator<E>
public abstract override /*1*/ /*fake_override*/ fun listIterator(/*0*/ index: jet.Int): jet.MutableListIterator<E>
@@ -5,11 +5,11 @@ public open class ModalityOfFakeOverrides : java.util.AbstractList<jet.String> {
protected final override /*1*/ /*fake_override*/ var modCount: jet.Int
public open override /*1*/ /*fake_override*/ fun add(/*0*/ p0: jet.Int, /*1*/ p1: jet.String): jet.Unit
public open override /*1*/ /*fake_override*/ fun add(/*0*/ p0: jet.String): jet.Boolean
public open override /*1*/ /*fake_override*/ fun addAll(/*0*/ p0: jet.Collection<jet.String>): jet.Boolean
public open override /*1*/ /*fake_override*/ fun addAll(/*0*/ c: jet.Collection<jet.String>): jet.Boolean
public open override /*1*/ /*fake_override*/ fun addAll(/*0*/ p0: jet.Int, /*1*/ p1: jet.Collection<jet.String>): jet.Boolean
public open override /*1*/ /*fake_override*/ fun clear(): jet.Unit
public open override /*1*/ /*fake_override*/ fun contains(/*0*/ p0: jet.Any?): jet.Boolean
public open override /*1*/ /*fake_override*/ fun containsAll(/*0*/ p0: jet.Collection<jet.Any?>): jet.Boolean
public open override /*1*/ /*fake_override*/ fun contains(/*0*/ o: jet.Any?): jet.Boolean
public open override /*1*/ /*fake_override*/ fun containsAll(/*0*/ c: jet.Collection<jet.Any?>): jet.Boolean
public open override /*1*/ fun get(/*0*/ p0: jet.Int): jet.String
public open override /*1*/ /*fake_override*/ fun indexOf(/*0*/ p0: jet.Any?): jet.Int
public open override /*1*/ /*fake_override*/ fun isEmpty(): jet.Boolean
@@ -17,11 +17,11 @@ public open class ModalityOfFakeOverrides : java.util.AbstractList<jet.String> {
public open override /*1*/ /*fake_override*/ fun lastIndexOf(/*0*/ p0: jet.Any?): jet.Int
public open override /*1*/ /*fake_override*/ fun listIterator(): jet.MutableListIterator<jet.String>
public open override /*1*/ /*fake_override*/ fun listIterator(/*0*/ p0: jet.Int): jet.MutableListIterator<jet.String>
public open override /*1*/ /*fake_override*/ fun remove(/*0*/ p0: jet.Any?): jet.Boolean
public open override /*1*/ /*fake_override*/ fun remove(/*0*/ o: jet.Any?): jet.Boolean
public open override /*1*/ /*fake_override*/ fun remove(/*0*/ p0: jet.Int): jet.String
public open override /*1*/ /*fake_override*/ fun removeAll(/*0*/ p0: jet.Collection<jet.Any?>): jet.Boolean
public open override /*1*/ /*fake_override*/ fun removeAll(/*0*/ c: jet.Collection<jet.Any?>): jet.Boolean
protected open override /*1*/ /*fake_override*/ fun removeRange(/*0*/ p0: jet.Int, /*1*/ p1: jet.Int): jet.Unit
public open override /*1*/ /*fake_override*/ fun retainAll(/*0*/ p0: jet.Collection<jet.Any?>): jet.Boolean
public open override /*1*/ /*fake_override*/ fun retainAll(/*0*/ c: jet.Collection<jet.Any?>): jet.Boolean
public open override /*1*/ /*fake_override*/ fun set(/*0*/ p0: jet.Int, /*1*/ p1: jet.String): jet.String
public open override /*1*/ fun size(): jet.Int
public open override /*1*/ /*fake_override*/ fun subList(/*0*/ p0: jet.Int, /*1*/ p1: jet.Int): jet.MutableList<jet.String>
@@ -0,0 +1,14 @@
package test
public trait Super1 {
public fun foo(): CharSequence
private fun bar(): String
}
public trait Super2 {
private fun foo(): String
public fun bar(): CharSequence
}
public trait Sub: Super1, Super2 {
}
@@ -0,0 +1,16 @@
package test
public trait Sub : test.Super1, test.Super2 {
public abstract override /*1*/ /*fake_override*/ fun bar(): jet.CharSequence
public abstract override /*1*/ /*fake_override*/ fun foo(): jet.CharSequence
}
public trait Super1 {
private abstract fun bar(): jet.String
public abstract fun foo(): jet.CharSequence
}
public trait Super2 {
public abstract fun bar(): jet.CharSequence
private abstract fun foo(): jet.String
}
@@ -0,0 +1,14 @@
package test
public trait Super1 {
val x: String
var y: String
}
public trait Super2 {
var x: String
val y: String
}
public trait Sub: Super1, Super2 {
}
@@ -0,0 +1,26 @@
package test
public trait Sub : test.Super1, test.Super2 {
internal abstract override /*2*/ /*fake_override*/ var x: jet.String
internal abstract override /*2*/ /*fake_override*/ fun <get-x>(): jet.String
internal abstract override /*1*/ /*fake_override*/ fun <set-x>(/*0*/ <set-?>: jet.String): jet.Unit
internal abstract override /*2*/ /*fake_override*/ var y: jet.String
internal abstract override /*2*/ /*fake_override*/ fun <get-y>(): jet.String
internal abstract override /*1*/ /*fake_override*/ fun <set-y>(/*0*/ <set-?>: jet.String): jet.Unit
}
public trait Super1 {
internal abstract val x: jet.String
internal abstract fun <get-x>(): jet.String
internal abstract var y: jet.String
internal abstract fun <get-y>(): jet.String
internal abstract fun <set-y>(/*0*/ <set-?>: jet.String): jet.Unit
}
public trait Super2 {
internal abstract var x: jet.String
internal abstract fun <get-x>(): jet.String
internal abstract fun <set-x>(/*0*/ <set-?>: jet.String): jet.Unit
internal abstract val y: jet.String
internal abstract fun <get-y>(): jet.String
}
@@ -0,0 +1,14 @@
package test
public trait Super1 {
val x: String
val y: CharSequence
}
public trait Super2 {
val x: CharSequence
val y: String
}
public trait Sub: Super1, Super2 {
}
@@ -0,0 +1,22 @@
package test
public trait Sub : test.Super1, test.Super2 {
internal abstract override /*2*/ /*fake_override*/ val x: jet.String
internal abstract override /*2*/ /*fake_override*/ fun <get-x>(): jet.String
internal abstract override /*2*/ /*fake_override*/ val y: jet.String
internal abstract override /*2*/ /*fake_override*/ fun <get-y>(): jet.String
}
public trait Super1 {
internal abstract val x: jet.String
internal abstract fun <get-x>(): jet.String
internal abstract val y: jet.CharSequence
internal abstract fun <get-y>(): jet.CharSequence
}
public trait Super2 {
internal abstract val x: jet.CharSequence
internal abstract fun <get-x>(): jet.CharSequence
internal abstract val y: jet.String
internal abstract fun <get-y>(): jet.String
}
@@ -444,6 +444,21 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadKotlin/fun"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("InheritMethodsDifferentReturnTypesAndVisibilities.kt")
public void testInheritMethodsDifferentReturnTypesAndVisibilities() throws Exception {
doTestWithAccessors("compiler/testData/loadKotlin/fun/InheritMethodsDifferentReturnTypesAndVisibilities.kt");
}
@TestMetadata("InheritValAndVar.kt")
public void testInheritValAndVar() throws Exception {
doTestWithAccessors("compiler/testData/loadKotlin/fun/InheritValAndVar.kt");
}
@TestMetadata("InheritValsDifferentTypes.kt")
public void testInheritValsDifferentTypes() throws Exception {
doTestWithAccessors("compiler/testData/loadKotlin/fun/InheritValsDifferentTypes.kt");
}
@TestMetadata("NoSamAdapter.kt")
public void testNoSamAdapter() throws Exception {
doTestWithAccessors("compiler/testData/loadKotlin/fun/NoSamAdapter.kt");
@@ -94,6 +94,16 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
doTest("compiler/testData/loadJava/compiledJavaCompareWithKotlin/FinalFieldAsVal.java");
}
@TestMetadata("InheritMethodsDifferentReturnTypes.java")
public void testInheritMethodsDifferentReturnTypes() throws Exception {
doTest("compiler/testData/loadJava/compiledJavaCompareWithKotlin/InheritMethodsDifferentReturnTypes.java");
}
@TestMetadata("InheritMethodsDifferentReturnTypesGeneric.java")
public void testInheritMethodsDifferentReturnTypesGeneric() throws Exception {
doTest("compiler/testData/loadJava/compiledJavaCompareWithKotlin/InheritMethodsDifferentReturnTypesGeneric.java");
}
@TestMetadata("InnerClass.java")
public void testInnerClass() throws Exception {
doTest("compiler/testData/loadJava/compiledJavaCompareWithKotlin/InnerClass.java");
@@ -446,6 +446,21 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadKotlin/fun"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("InheritMethodsDifferentReturnTypesAndVisibilities.kt")
public void testInheritMethodsDifferentReturnTypesAndVisibilities() throws Exception {
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/fun/InheritMethodsDifferentReturnTypesAndVisibilities.kt");
}
@TestMetadata("InheritValAndVar.kt")
public void testInheritValAndVar() throws Exception {
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/fun/InheritValAndVar.kt");
}
@TestMetadata("InheritValsDifferentTypes.kt")
public void testInheritValsDifferentTypes() throws Exception {
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/fun/InheritValsDifferentTypes.kt");
}
@TestMetadata("NoSamAdapter.kt")
public void testNoSamAdapter() throws Exception {
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/fun/NoSamAdapter.kt");
@@ -1186,6 +1201,16 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/compiledJavaCompareWithKotlin/FinalFieldAsVal.kt");
}
@TestMetadata("InheritMethodsDifferentReturnTypes.kt")
public void testInheritMethodsDifferentReturnTypes() throws Exception {
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/compiledJavaCompareWithKotlin/InheritMethodsDifferentReturnTypes.kt");
}
@TestMetadata("InheritMethodsDifferentReturnTypesGeneric.kt")
public void testInheritMethodsDifferentReturnTypesGeneric() throws Exception {
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/compiledJavaCompareWithKotlin/InheritMethodsDifferentReturnTypesGeneric.kt");
}
@TestMetadata("InnerClass.kt")
public void testInnerClass() throws Exception {
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/compiledJavaCompareWithKotlin/InnerClass.kt");