KT-3301 Inference with several supertypes fails

#KT-3301 fixed
This commit is contained in:
Svetlana Isakova
2013-01-30 20:29:30 +04:00
parent 3c82e80745
commit ba9c455ea1
3 changed files with 46 additions and 0 deletions
@@ -33,6 +33,12 @@ public class ConstraintsUtil {
public static Set<JetType> getValues(@Nullable TypeConstraints typeConstraints) {
Set<JetType> values = Sets.newLinkedHashSet();
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());
if (!typeConstraints.getLowerBounds().isEmpty()) {
JetType superTypeOfLowerBounds = CommonSupertypes.commonSupertype(typeConstraints.getLowerBounds());
@@ -63,6 +69,21 @@ public class ConstraintsUtil {
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
public static JetType getValue(@Nullable TypeConstraints typeConstraints) {
//todo all checks