try intersection of upper bounds as a suggestion
not each bound itself while resolving constraint system
This commit is contained in:
@@ -0,0 +1,30 @@
|
|||||||
|
package s
|
||||||
|
|
||||||
|
trait In<in T>
|
||||||
|
|
||||||
|
trait A
|
||||||
|
trait B
|
||||||
|
trait C: A, B
|
||||||
|
|
||||||
|
fun <T> foo(in1: In<T>, in2: In<T>): T = throw Exception("$in1 $in2")
|
||||||
|
|
||||||
|
fun test(inA: In<A>, inB: In<B>, inC: In<C>) {
|
||||||
|
|
||||||
|
<!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>foo<!>(inA, inB)
|
||||||
|
|
||||||
|
val r = foo(inA, inC)
|
||||||
|
r: C
|
||||||
|
|
||||||
|
val c: C = foo(inA, inB)
|
||||||
|
|
||||||
|
use(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T: C> bar(in1: In<T>): T = throw Exception("$in1")
|
||||||
|
|
||||||
|
fun test(inA: In<A>) {
|
||||||
|
val r = bar(inA)
|
||||||
|
r: C
|
||||||
|
}
|
||||||
|
|
||||||
|
fun use(vararg a: Any?) = a
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
fun <R : Any> unescape(value: Any): R? = throw Exception("$value")
|
||||||
|
|
||||||
|
fun <T: Any> foo(v: Any): T? = unescape(v)
|
||||||
|
|
||||||
|
//--------------
|
||||||
|
|
||||||
|
trait A
|
||||||
|
|
||||||
|
fun <R : A> unescapeA(value: Any): R? = throw Exception("$value")
|
||||||
|
|
||||||
|
|
||||||
|
fun <T: A> fooA(v: Any): T? = unescapeA(v)
|
||||||
|
|
||||||
@@ -3542,11 +3542,21 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
|||||||
doTest("compiler/testData/diagnostics/tests/inference/upperBounds/doNotInferFromBoundsOnly.kt");
|
doTest("compiler/testData/diagnostics/tests/inference/upperBounds/doNotInferFromBoundsOnly.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("intersectUpperBounds.kt")
|
||||||
|
public void testIntersectUpperBounds() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/inference/upperBounds/intersectUpperBounds.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt2856.kt")
|
@TestMetadata("kt2856.kt")
|
||||||
public void testKt2856() throws Exception {
|
public void testKt2856() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/inference/upperBounds/kt2856.kt");
|
doTest("compiler/testData/diagnostics/tests/inference/upperBounds/kt2856.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nonNullUpperBound.kt")
|
||||||
|
public void testNonNullUpperBound() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/inference/upperBounds/nonNullUpperBound.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("useBoundsIfUnknownParameters.kt")
|
@TestMetadata("useBoundsIfUnknownParameters.kt")
|
||||||
public void testUseBoundsIfUnknownParameters() throws Exception {
|
public void testUseBoundsIfUnknownParameters() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsIfUnknownParameters.kt");
|
doTest("compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsIfUnknownParameters.kt");
|
||||||
|
|||||||
+4
-3
@@ -186,9 +186,10 @@ public class TypeConstraintsImpl implements TypeConstraints {
|
|||||||
ContainerUtil.addIfNotNull(superTypeOfLowerBounds, values);
|
ContainerUtil.addIfNotNull(superTypeOfLowerBounds, values);
|
||||||
|
|
||||||
Set<JetType> upperBounds = filterBounds(constraints, BoundKind.UPPER_BOUND, values);
|
Set<JetType> upperBounds = filterBounds(constraints, BoundKind.UPPER_BOUND, values);
|
||||||
for (JetType upperBound : upperBounds) {
|
JetType intersectionOfUpperBounds = TypeUtils.intersect(JetTypeChecker.INSTANCE, upperBounds);
|
||||||
if (trySuggestion(upperBound, constraints)) {
|
if (!upperBounds.isEmpty() && intersectionOfUpperBounds != null) {
|
||||||
return Collections.singleton(upperBound);
|
if (trySuggestion(intersectionOfUpperBounds, constraints)) {
|
||||||
|
return Collections.singleton(intersectionOfUpperBounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//todo
|
//todo
|
||||||
|
|||||||
Reference in New Issue
Block a user