fixed bug in constraint system

For parameter type T constraint T? <: Int? should NOT transform to T <: Int, it should be T <: Int?
equality constraint T? = Int? should transform to T <: Int? && T >: Int
This commit is contained in:
Svetlana Isakova
2013-09-19 17:23:34 +04:00
parent d4aaed2787
commit 9a0ec7949e
7 changed files with 152 additions and 5 deletions
@@ -336,11 +336,21 @@ public class ConstraintSystemImpl implements ConstraintSystem {
TypeConstraintsImpl typeConstraints = getTypeConstraints(parameterType);
assert typeConstraints != null : "constraint should be generated only for type variables";
if (parameterType.isNullable()) {
// For parameter type T constraint T? <: Int? should transform to T <: Int
constrainingType = TypeUtils.makeNotNullable(constrainingType);
if (!parameterType.isNullable() || !constrainingType.isNullable()) {
typeConstraints.addBound(boundKind, constrainingType);
return;
}
// For parameter type T:
// constraint T? = Int? should transform to T >: Int and T <: Int?
// constraint T? >: Int? should transform to T >: Int
JetType notNullConstrainingType = TypeUtils.makeNotNullable(constrainingType);
if (boundKind == EXACT_BOUND || boundKind == LOWER_BOUND) {
typeConstraints.addBound(LOWER_BOUND, notNullConstrainingType);
}
// constraint T? <: Int? should transform to T <: Int?
if (boundKind == EXACT_BOUND || boundKind == UPPER_BOUND) {
typeConstraints.addBound(UPPER_BOUND, constrainingType);
}
typeConstraints.addBound(boundKind, constrainingType);
}
public void processDeclaredBoundConstraints() {