KT-3301 Inference with several supertypes fails
#KT-3301 fixed
This commit is contained in:
+21
@@ -33,6 +33,12 @@ public class ConstraintsUtil {
|
|||||||
public static Set<JetType> getValues(@Nullable TypeConstraints typeConstraints) {
|
public static Set<JetType> getValues(@Nullable TypeConstraints typeConstraints) {
|
||||||
Set<JetType> values = Sets.newLinkedHashSet();
|
Set<JetType> values = Sets.newLinkedHashSet();
|
||||||
if (typeConstraints != null && !typeConstraints.isEmpty()) {
|
if (typeConstraints != null && !typeConstraints.isEmpty()) {
|
||||||
|
if (typeConstraints.getExactBounds().size() == 1) {
|
||||||
|
if (verifyOneExactBound(typeConstraints)) {
|
||||||
|
JetType exactBound = typeConstraints.getExactBounds().iterator().next();
|
||||||
|
return Collections.singleton(exactBound);
|
||||||
|
}
|
||||||
|
}
|
||||||
values.addAll(typeConstraints.getExactBounds());
|
values.addAll(typeConstraints.getExactBounds());
|
||||||
if (!typeConstraints.getLowerBounds().isEmpty()) {
|
if (!typeConstraints.getLowerBounds().isEmpty()) {
|
||||||
JetType superTypeOfLowerBounds = CommonSupertypes.commonSupertype(typeConstraints.getLowerBounds());
|
JetType superTypeOfLowerBounds = CommonSupertypes.commonSupertype(typeConstraints.getLowerBounds());
|
||||||
@@ -63,6 +69,21 @@ public class ConstraintsUtil {
|
|||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean verifyOneExactBound(@NotNull TypeConstraints typeConstraints) {
|
||||||
|
JetType exactBound = typeConstraints.getExactBounds().iterator().next();
|
||||||
|
for (JetType lowerBound : typeConstraints.getLowerBounds()) {
|
||||||
|
if (!JetTypeChecker.INSTANCE.isSubtypeOf(lowerBound, exactBound)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (JetType upperBound : typeConstraints.getUpperBounds()) {
|
||||||
|
if (!JetTypeChecker.INSTANCE.isSubtypeOf(exactBound, upperBound)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static JetType getValue(@Nullable TypeConstraints typeConstraints) {
|
public static JetType getValue(@Nullable TypeConstraints typeConstraints) {
|
||||||
//todo all checks
|
//todo all checks
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
//KT-3301 Inference with several supertypes fails
|
||||||
|
|
||||||
|
package arrays
|
||||||
|
|
||||||
|
trait A
|
||||||
|
trait B
|
||||||
|
|
||||||
|
object CAB : A, B
|
||||||
|
object DAB : A, B
|
||||||
|
|
||||||
|
fun m(<!UNUSED_PARAMETER!>args<!> : Array<A>) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test122() {
|
||||||
|
m(array(CAB, DAB)) // Wrong error here: Array<Any> is inferred while expected Array<A> is satisfied
|
||||||
|
}
|
||||||
|
|
||||||
|
//from library
|
||||||
|
fun array<T>(vararg <!UNUSED_PARAMETER!>t<!>: T): Array<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||||
@@ -2294,6 +2294,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
|||||||
doTest("compiler/testData/diagnostics/tests/inference/regressions/kt3174.kt");
|
doTest("compiler/testData/diagnostics/tests/inference/regressions/kt3174.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt3301.kt")
|
||||||
|
public void testKt3301() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/inference/regressions/kt3301.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt702.kt")
|
@TestMetadata("kt702.kt")
|
||||||
public void testKt702() throws Exception {
|
public void testKt702() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/inference/regressions/kt702.kt");
|
doTest("compiler/testData/diagnostics/tests/inference/regressions/kt702.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user