Type variable with non-trivial upper bound cannot capture 'in' projection
This commit is contained in:
+6
-1
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user