Fixed inference in a simple case.

Try number lower bounds before upper bounds when computing a value.
This commit is contained in:
svtk
2013-11-19 23:03:52 +04:00
parent 9d3a7804cc
commit 1a34dffb1f
4 changed files with 50 additions and 29 deletions
@@ -185,19 +185,10 @@ public class TypeBoundsImpl implements TypeBounds {
}
ContainerUtil.addIfNotNull(superTypeOfLowerBounds, values);
Set<JetType> upperBounds = filterBounds(bounds, BoundKind.UPPER_BOUND, values);
JetType intersectionOfUpperBounds = TypeUtils.intersect(JetTypeChecker.INSTANCE, upperBounds);
if (!upperBounds.isEmpty() && intersectionOfUpperBounds != null) {
if (tryPossibleAnswer(intersectionOfUpperBounds)) {
return Collections.singleton(intersectionOfUpperBounds);
}
}
//todo
//fun <T> foo(t: T, consumer: Consumer<T>): T
//foo(1, c: Consumer<Any>) - infer Int, not Any here
values.addAll(filterBounds(bounds, BoundKind.UPPER_BOUND));
JetType superTypeOfNumberLowerBounds = TypeUtils.commonSupertypeForNumberTypes(numberLowerBounds);
if (tryPossibleAnswer(superTypeOfNumberLowerBounds)) {
return Collections.singleton(superTypeOfNumberLowerBounds);
@@ -211,6 +202,17 @@ public class TypeBoundsImpl implements TypeBounds {
return Collections.singleton(superTypeOfAllLowerBounds);
}
}
Set<JetType> upperBounds = filterBounds(bounds, BoundKind.UPPER_BOUND, values);
JetType intersectionOfUpperBounds = TypeUtils.intersect(JetTypeChecker.INSTANCE, upperBounds);
if (!upperBounds.isEmpty() && intersectionOfUpperBounds != null) {
if (tryPossibleAnswer(intersectionOfUpperBounds)) {
return Collections.singleton(intersectionOfUpperBounds);
}
}
values.addAll(filterBounds(bounds, BoundKind.UPPER_BOUND));
return values;
}