diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java index 13921ded53e..cba2dca4683 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java @@ -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 conflictingTypes) { - for (Iterator 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 conflictingTypes) { + for (Iterator 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); diff --git a/compiler/testData/codegen/box/builtinStubMethods/twoListsInSupertypes.kt b/compiler/testData/codegen/box/builtinStubMethods/twoListsInSupertypes.kt deleted file mode 100644 index d989ac5ba15..00000000000 --- a/compiler/testData/codegen/box/builtinStubMethods/twoListsInSupertypes.kt +++ /dev/null @@ -1,26 +0,0 @@ -trait ListAny : List -trait ListString : List - -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 = null!! - override fun containsAll(c: Collection): 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 = null!! - override fun listIterator(index: Int): ListIterator = null!! - override fun subList(fromIndex: Int, toIndex: Int): List = null!! -} - -fun box(): String { - val a = A() as MutableList - a.add("Fail") - return "OK" -} diff --git a/compiler/testData/diagnostics/tests/GenericArgumentConsistency.kt b/compiler/testData/diagnostics/tests/GenericArgumentConsistency.kt index dc5dddb65dc..d95b35b7eec 100644 --- a/compiler/testData/diagnostics/tests/GenericArgumentConsistency.kt +++ b/compiler/testData/diagnostics/tests/GenericArgumentConsistency.kt @@ -2,12 +2,12 @@ trait A {} trait B : A {} trait C : B, A {} -trait C1 : B, A {} +trait C1 : B, A {} trait D : C, B{} trait A1 {} trait B1 : A1 {} -trait B2 : A1, B1 {} +trait B2 : A1, B1 {} trait BA1 {} trait BB1 : BA1 {} @@ -19,7 +19,7 @@ package x trait AA1 {} trait AB1 : AA1 {} trait AB3 : AA1> {} - trait AB2 : AA1, AB1, AB3 {} + trait AB2 : AA1, AB1, AB3 {} // FILE: b.kt package x2 @@ -33,11 +33,11 @@ package x3 trait AA1 {} trait AB1 : AA1 {} trait AB3 : AA1> {} - trait AB2 : AA1, AB1, AB3 {} + trait AB2 : AA1, AB1, AB3 {} // FILE: b.kt package sx2 trait AA1 {} trait AB1 : AA1 {} trait AB3 : AA1> {} - trait AB2 : AA1, AB1, AB3 {} + trait AB2 : AA1, AB1, AB3 {} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java index 5035f3944dd..c4fb2838cec 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -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) diff --git a/idea/testData/checker/GenericArgumentConsistency.kt b/idea/testData/checker/GenericArgumentConsistency.kt index 6b7a0b9be43..650637388cd 100644 --- a/idea/testData/checker/GenericArgumentConsistency.kt +++ b/idea/testData/checker/GenericArgumentConsistency.kt @@ -1,12 +1,12 @@ trait A {} trait B : A {} trait C : B, A {} -trait C1 : B, A {} -trait D : C, B{} +trait C1 : B, A {} +trait D : C, B{} trait A1 {} trait B1 : A1 {} -trait B2 : A1, B1 {} +trait B2 : A1, B1 {} trait BA1 {} trait BB1 : BA1 {} @@ -17,7 +17,7 @@ trait BB2 : BA1, BB1 {} trait xAA1 {} trait xAB1 : xAA1 {} trait xAB3 : xAA1> {} - trait xAB2 : xAA1, xAB1, xAB3 {} + trait xAB2 : xAA1, xAB1, xAB3 {} //} //package x2 { @@ -31,7 +31,7 @@ trait BB2 : BA1, BB1 {} trait x3AA1 {} trait x3AB1 : x3AA1 {} trait x3AB3 : x3AA1> {} - trait x3AB2 : x3AA1, x3AB1, x3AB3 {} + trait x3AB2 : x3AA1, x3AB1, x3AB3 {} //} //package sx2 {