if some type parameter has only weak constraints (from bounds), then we consider it as unknown

This commit is contained in:
Svetlana Isakova
2013-09-26 14:41:48 +04:00
parent 731efd0781
commit cb25e1d55a
3 changed files with 83 additions and 0 deletions
@@ -0,0 +1,69 @@
package a
trait A
fun <T> emptyList(): List<T> = throw Exception()
fun test1() {
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>emptyList<!>()
}
//--------------
fun <T: A> emptyListOfA(): List<T> = throw Exception()
fun test2() {
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>emptyListOfA<!>()
}
//--------------
fun <T: A, R: T> emptyStrangeMap(): Map<T, R> = throw Exception()
fun test3() {
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>emptyStrangeMap<!>()
}
//--------------
fun <T, R: T> emptyStrangeMap1(t: T): Map<T, R> = throw Exception("$t")
fun test4() {
//todo we may infer 'Int' for 'R' here
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>emptyStrangeMap1<!>(1)
}
//--------------
fun <T: A, R: T> emptyStrangeMap2(t: T): Map<T, R> where R: A = throw Exception("$t")
fun test5(a: A) {
//todo we may infer 'A' for 'R' here
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>emptyStrangeMap2<!>(a)
}
//--------------
fun <T: A, R: T> emptyStrangeMap3(r: R): Map<T, R> = throw Exception("$r")
fun test6(a: A) {
emptyStrangeMap3(a)
}
//--------------
fun <T, R: T> emptyStrangeMap4(l: MutableList<T>): Map<T, R> = throw Exception("$l")
fun test7(list: MutableList<Int>) {
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>emptyStrangeMap4<!>(list)
}
//--------------
fun test7() : Map<A, A> = emptyStrangeMap()
//--------------
fun <U, V: U> foo(): U = throw Exception()
fun test8(): Int = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>()
@@ -3537,6 +3537,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/diagnostics/tests/inference/upperBounds"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("doNotInferFromBoundsOnly.kt")
public void testDoNotInferFromBoundsOnly() throws Exception {
doTest("compiler/testData/diagnostics/tests/inference/upperBounds/doNotInferFromBoundsOnly.kt");
}
@TestMetadata("kt2856.kt")
public void testKt2856() throws Exception {
doTest("compiler/testData/diagnostics/tests/inference/upperBounds/kt2856.kt");
@@ -155,6 +155,15 @@ public class TypeConstraintsImpl implements TypeConstraints {
if (constraints.isEmpty()) {
return Collections.emptyList();
}
boolean hasStrongConstraint = ContainerUtil.exists(constraints, new Condition<Constraint>() {
@Override
public boolean value(Constraint constraint) {
return constraint.constraintPosition.isStrong();
}
});
if (!hasStrongConstraint) {
return Collections.emptyList();
}
Set<JetType> exactBounds = filterBounds(constraints, BoundKind.EXACT_BOUND, values);
if (exactBounds.size() == 1) {