drop covariant specialisation for supertypes
This commit is contained in:
committed by
Andrey Breslav
parent
9de5acf9a6
commit
991db29731
@@ -201,21 +201,7 @@ public class DeclarationsChecker {
|
||||
for (TypeProjection projection : projections) {
|
||||
conflictingTypes.add(projection.getType());
|
||||
}
|
||||
switch (typeParameterDescriptor.getVariance()) {
|
||||
case INVARIANT:
|
||||
// Leave conflicting types as is
|
||||
Filter.REMOVE_IF_EQUAL_TYPE_IN_THE_SET.proceed(conflictingTypes);
|
||||
break;
|
||||
case IN_VARIANCE:
|
||||
// Filter out those who have supertypes in this set (common supertype)
|
||||
Filter.REMOVE_IF_SUPERTYPE_IN_THE_SET.proceed(conflictingTypes);
|
||||
break;
|
||||
case OUT_VARIANCE:
|
||||
// Filter out those who have subtypes in this set (common subtype)
|
||||
Filter.REMOVE_IF_SUBTYPE_IN_THE_SET.proceed(conflictingTypes);
|
||||
break;
|
||||
}
|
||||
|
||||
removeDuplicateTypes(conflictingTypes);
|
||||
if (conflictingTypes.size() > 1) {
|
||||
DeclarationDescriptor containingDeclaration = typeParameterDescriptor.getContainingDeclaration();
|
||||
assert containingDeclaration instanceof ClassDescriptor : containingDeclaration;
|
||||
@@ -231,42 +217,18 @@ public class DeclarationsChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private enum Filter {
|
||||
REMOVE_IF_SUBTYPE_IN_THE_SET {
|
||||
@Override
|
||||
public boolean removeNeeded(JetType subject, JetType other) {
|
||||
return JetTypeChecker.DEFAULT.isSubtypeOf(other, subject);
|
||||
}
|
||||
},
|
||||
REMOVE_IF_SUPERTYPE_IN_THE_SET {
|
||||
@Override
|
||||
public boolean removeNeeded(JetType subject, JetType other) {
|
||||
return JetTypeChecker.DEFAULT.isSubtypeOf(subject, other);
|
||||
}
|
||||
},
|
||||
REMOVE_IF_EQUAL_TYPE_IN_THE_SET {
|
||||
@Override
|
||||
public boolean removeNeeded(JetType subject, JetType other) {
|
||||
return JetTypeChecker.DEFAULT.equalTypes(subject, other);
|
||||
}
|
||||
};
|
||||
|
||||
private void proceed(Set<JetType> conflictingTypes) {
|
||||
for (Iterator<JetType> iterator = conflictingTypes.iterator(); iterator.hasNext(); ) {
|
||||
JetType type = iterator.next();
|
||||
for (JetType otherType : conflictingTypes) {
|
||||
boolean subtypeOf = removeNeeded(type, otherType);
|
||||
if (type != otherType && subtypeOf) {
|
||||
iterator.remove();
|
||||
break;
|
||||
}
|
||||
private static void removeDuplicateTypes(Set<JetType> conflictingTypes) {
|
||||
for (Iterator<JetType> iterator = conflictingTypes.iterator(); iterator.hasNext(); ) {
|
||||
JetType type = iterator.next();
|
||||
for (JetType otherType : conflictingTypes) {
|
||||
boolean subtypeOf = JetTypeChecker.DEFAULT.equalTypes(type, otherType);
|
||||
if (type != otherType && subtypeOf) {
|
||||
iterator.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract boolean removeNeeded(JetType subject, JetType other);
|
||||
}
|
||||
|
||||
private void checkObject(JetObjectDeclaration declaration, ClassDescriptor classDescriptor) {
|
||||
checkDeprecatedClassObjectSyntax(declaration);
|
||||
reportErrorIfHasIllegalModifier(declaration);
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
trait ListAny : List<Any>
|
||||
trait ListString : List<String>
|
||||
|
||||
trait AddStringImpl {
|
||||
fun add(s: String) {}
|
||||
}
|
||||
|
||||
class A : ListAny, ListString, AddStringImpl {
|
||||
override fun size(): Int = 0
|
||||
override fun isEmpty(): Boolean = true
|
||||
override fun contains(o: Any?): Boolean = false
|
||||
override fun iterator(): Iterator<String> = null!!
|
||||
override fun containsAll(c: Collection<Any?>): Boolean = false
|
||||
override fun get(index: Int): String = null!!
|
||||
override fun indexOf(o: Any?): Int = -1
|
||||
override fun lastIndexOf(o: Any?): Int = -1
|
||||
override fun listIterator(): ListIterator<String> = null!!
|
||||
override fun listIterator(index: Int): ListIterator<String> = null!!
|
||||
override fun subList(fromIndex: Int, toIndex: Int): List<String> = null!!
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A() as MutableList<String>
|
||||
a.add("Fail")
|
||||
return "OK"
|
||||
}
|
||||
@@ -2,12 +2,12 @@
|
||||
trait A<in T> {}
|
||||
trait B<T> : A<Int> {}
|
||||
trait C<T> : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>B<T>, A<T><!> {}
|
||||
trait C1<T> : B<T>, A<Any> {}
|
||||
trait C1<T> : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>B<T>, A<Any><!> {}
|
||||
trait D : <!INCONSISTENT_TYPE_PARAMETER_VALUES, INCONSISTENT_TYPE_PARAMETER_VALUES!>C<Boolean>, B<Double><!>{}
|
||||
|
||||
trait A1<out T> {}
|
||||
trait B1 : A1<Int> {}
|
||||
trait B2 : A1<Any>, B1 {}
|
||||
trait B2 : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>A1<Any>, B1<!> {}
|
||||
|
||||
trait BA1<T> {}
|
||||
trait BB1 : BA1<Int> {}
|
||||
@@ -19,7 +19,7 @@ package x
|
||||
trait AA1<out T> {}
|
||||
trait AB1 : AA1<Int> {}
|
||||
trait AB3 : AA1<Comparable<Int>> {}
|
||||
trait AB2 : AA1<Number>, AB1, AB3 {}
|
||||
trait AB2 : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>AA1<Number>, AB1, AB3<!> {}
|
||||
|
||||
// FILE: b.kt
|
||||
package x2
|
||||
@@ -33,11 +33,11 @@ package x3
|
||||
trait AA1<in T> {}
|
||||
trait AB1 : AA1<Any> {}
|
||||
trait AB3 : AA1<Comparable<Int>> {}
|
||||
trait AB2 : AA1<Number>, AB1, AB3 {}
|
||||
trait AB2 : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>AA1<Number>, AB1, AB3<!> {}
|
||||
|
||||
// FILE: b.kt
|
||||
package sx2
|
||||
trait AA1<in T> {}
|
||||
trait AB1 : AA1<Int> {}
|
||||
trait AB3 : AA1<Comparable<Int>> {}
|
||||
trait AB2 : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>AA1<Number>, AB1, AB3<!> {}
|
||||
trait AB2 : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>AA1<Number>, AB1, AB3<!> {}
|
||||
-6
@@ -769,12 +769,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("twoListsInSupertypes.kt")
|
||||
public void testTwoListsInSupertypes() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/builtinStubMethods/twoListsInSupertypes.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/builtinStubMethods/extendJavaCollections")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
trait A<in T> {}
|
||||
trait B<T> : A<Int> {}
|
||||
trait C<T> : <error>B<T>, A<T></error> {}
|
||||
trait C1<T> : B<T>, A<Any> {}
|
||||
trait D : <error>C<Boolean>, B<Double></error>{}
|
||||
trait C1<T> : <error>B<T>, A<Any></error> {}
|
||||
trait D : <error><error>C<Boolean>, B<Double></error></error>{}
|
||||
|
||||
trait A1<out T> {}
|
||||
trait B1 : A1<Int> {}
|
||||
trait B2 : A1<Any>, B1 {}
|
||||
trait B2 : <error>A1<Any>, B1</error> {}
|
||||
|
||||
trait BA1<T> {}
|
||||
trait BB1 : BA1<Int> {}
|
||||
@@ -17,7 +17,7 @@ trait BB2 : <error>BA1<Any>, BB1</error> {}
|
||||
trait xAA1<out T> {}
|
||||
trait xAB1 : xAA1<Int> {}
|
||||
trait xAB3 : xAA1<Comparable<Int>> {}
|
||||
trait xAB2 : xAA1<Number>, xAB1, xAB3 {}
|
||||
trait xAB2 : <error>xAA1<Number>, xAB1, xAB3</error> {}
|
||||
//}
|
||||
|
||||
//package x2 {
|
||||
@@ -31,7 +31,7 @@ trait BB2 : <error>BA1<Any>, BB1</error> {}
|
||||
trait x3AA1<in T> {}
|
||||
trait x3AB1 : x3AA1<Any> {}
|
||||
trait x3AB3 : x3AA1<Comparable<Int>> {}
|
||||
trait x3AB2 : x3AA1<Number>, x3AB1, x3AB3 {}
|
||||
trait x3AB2 : <error>x3AA1<Number>, x3AB1, x3AB3</error> {}
|
||||
//}
|
||||
|
||||
//package sx2 {
|
||||
|
||||
Reference in New Issue
Block a user