Ignore constraint from implicit 'in Nothing'

From Array<T> <: Array<out Int> we may generate T >: Nothing (implicit) and T <: Int (explicit).
Without ignoring we'll infer 'Nothing' for T too often
This commit is contained in:
Svetlana Isakova
2014-12-19 19:24:49 +03:00
parent 70f6fcadc9
commit 6489ff2cb6
5 changed files with 39 additions and 5 deletions
@@ -160,10 +160,6 @@ public class TypeBoundsImpl(
// a captured type might be an answer
if (!possibleAnswer.getConstructor().isDenotable() && !possibleAnswer.isCaptured()) return false
// e.g. if T has a lower bound 'Nothing' and an upper bound 'String',
// by default 'Nothing' is inferred which can lead to an error for reified type variable
if (typeVariable.isReified() && possibleAnswer.cannotBeReified()) return false
for (bound in bounds) {
when (bound.kind) {
LOWER_BOUND -> if (!JetTypeChecker.DEFAULT.isSubtypeOf(bound.constrainingType, possibleAnswer)) {
@@ -244,7 +244,12 @@ public class TypeCheckingProcedure {
}
else {
if (!constraints.assertSubtype(subOut, superOut, this)) return false;
if (!constraints.assertSubtype(superIn, subIn, this)) return false;
if (superArgument.getProjectionKind() != Variance.OUT_VARIANCE) {
if (!constraints.assertSubtype(superIn, subIn, this)) return false;
}
else {
assert KotlinBuiltIns.isNothing(superIn) : "In component must be Nothing for out-projection";
}
}
}
return true;