diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsUtil.java index fb0deafb134..3e8a3b4a99c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsUtil.java @@ -48,16 +48,11 @@ public class ConstraintsUtil { } values.addAll(exactBounds); - Collection lowerBounds = Sets.newHashSet(); - Collection numberLowerBounds = Sets.newHashSet(); - for (JetType lowerBound : typeConstraintsWithoutErrorTypes.getLowerBounds()) { - if (lowerBound.getConstructor() instanceof NumberValueTypeConstructor) { - numberLowerBounds.add(lowerBound); - } - else { - lowerBounds.add(lowerBound); - } - } + Pair, Collection> pair = + TypeUtils.filterNumberTypes(typeConstraintsWithoutErrorTypes.getLowerBounds()); + Collection lowerBounds = pair.getFirst(); + Collection numberLowerBounds = pair.getSecond(); + JetType superTypeOfLowerBounds = commonSupertype(lowerBounds); if (trySuggestion(superTypeOfLowerBounds, typeConstraints)) { return Collections.singleton(superTypeOfLowerBounds); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java index a11402b0d4f..9b2575dcfb7 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java @@ -21,6 +21,7 @@ import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import com.intellij.openapi.util.Pair; import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -616,4 +617,30 @@ public class TypeUtils { } return getDefaultPrimitiveNumberType(numberValueTypeConstructor); } + + @NotNull + public static Pair, Collection> filterNumberTypes(@NotNull Collection types) { + Collection numberTypes = Sets.newLinkedHashSet(); + Collection otherTypes = Sets.newLinkedHashSet(); + for (JetType type : types) { + if (type.getConstructor() instanceof NumberValueTypeConstructor) { + numberTypes.add(type); + } + else { + otherTypes.add(type); + } + } + return Pair.create(otherTypes, numberTypes); + } + + @NotNull + public static JetType commonSupertypeForPossiblyNumberTypes(@NotNull Collection types) { + Pair, Collection> pair = filterNumberTypes(types); + Collection numberTypes = pair.getSecond(); + Collection otherTypes = pair.getFirst(); + if (!numberTypes.isEmpty()) { + otherTypes.add(commonSupertypeForNumberTypes(numberTypes)); + } + return CommonSupertypes.commonSupertype(otherTypes); + } }