Constraint Foo on T! should be turned into Foo! on T

This commit is contained in:
Andrey Breslav
2014-08-25 17:55:30 +04:00
parent 6cb1d2e3f7
commit 141e731f39
3 changed files with 30 additions and 0 deletions
@@ -413,6 +413,23 @@ public class ConstraintSystemImpl implements ConstraintSystem {
@NotNull TypeBoundsImpl.BoundKind boundKind,
@NotNull ConstraintPosition constraintPosition
) {
// Here we are handling the case when T! gets a bound Foo (or Foo?)
// In this case, type parameter T is supposed to get the bound Foo!
// Example:
// val c: Collection<Foo> = Collections.singleton(null : Foo?)
// Constraints for T are:
// Foo? <: T!
// Foo >: T!
// both Foo and Foo? transform to Foo! here
if (TypesPackage.isFlexible(parameterType)) {
if (parameterType instanceof CustomTypeVariable) {
CustomTypeVariable typeVariable = (CustomTypeVariable) parameterType;
if (typeVariable.getIsTypeVariable()) {
constrainingType = typeVariable.substitutionResult(constrainingType);
}
}
}
TypeBoundsImpl typeBounds = getTypeBounds(parameterType);
assert typeBounds != null : "constraint should be generated only for type variables";