Fix: constraint T? >: Int! should transform to T >: Int

This commit is contained in:
Svetlana Isakova
2015-01-28 18:51:55 +03:00
parent f5fb3246ae
commit a2f03f2d52
4 changed files with 45 additions and 3 deletions
@@ -333,18 +333,20 @@ public class ConstraintSystemImpl : ConstraintSystem {
val typeBounds = getTypeBounds(parameterType)
if (!parameterType.isMarkedNullable() || !newConstrainingType.isMarkedNullable()) {
if (!parameterType.isMarkedNullable() || !TypeUtils.isNullableType(newConstrainingType)) {
typeBounds.addBound(boundKind, newConstrainingType, constraintPosition)
return
}
// For parameter type T:
// constraint T? = Int? should transform to T >: Int and T <: Int?
// constraint T? >: Int? should transform to T >: Int
// constraint T? = Int! should transform to T >: Int and T <: Int!
// constraints T? >: Int?; T? >: Int! should transform to T >: Int
val notNullConstrainingType = TypeUtils.makeNotNullable(newConstrainingType)
if (boundKind == EXACT_BOUND || boundKind == LOWER_BOUND) {
typeBounds.addBound(LOWER_BOUND, notNullConstrainingType, constraintPosition)
}
// constraint T? <: Int? should transform to T <: Int?
// constraints T? <: Int?; T? <: Int! should transform to T <: Int?; T <: Int! correspondingly
if (boundKind == EXACT_BOUND || boundKind == UPPER_BOUND) {
typeBounds.addBound(UPPER_BOUND, newConstrainingType, constraintPosition)
}