Type variable with non-trivial upper bound cannot capture 'in' projection

This commit is contained in:
Svetlana Isakova
2014-12-11 18:49:16 +03:00
parent 8b0707b15d
commit 1f6f607f40
6 changed files with 50 additions and 2 deletions
@@ -379,7 +379,12 @@ public class ConstraintSystemImpl : ConstraintSystem {
constrainingTypeProjection: TypeProjection,
constraintPosition: ConstraintPosition
) {
val typeBounds = getTypeBounds(parameterType)
val typeVariable = getMyTypeVariable(parameterType)!!
if (!KotlinBuiltIns.isNullableAny(typeVariable.getUpperBoundsAsType())
&& constrainingTypeProjection.getProjectionKind() == Variance.IN_VARIANCE) {
cannotCaptureTypesError = true
}
val typeBounds = getTypeBounds(typeVariable)
val typeProjection = if (parameterType.isMarkedNullable()) {
TypeProjectionImpl(constrainingTypeProjection.getProjectionKind(), TypeUtils.makeNotNullable(constrainingTypeProjection.getType()))
}
@@ -878,6 +878,10 @@ public class KotlinBuiltIns {
return isConstructedFromGivenClass(type, FQ_NAMES.any);
}
public static boolean isNullableAny(@NotNull JetType type) {
return isAnyOrNullableAny(type) && type.isMarkedNullable();
}
public static boolean isUnit(@NotNull JetType type) {
return isNotNullConstructedFromGivenClass(type, FQ_NAMES.unit);
}