moved 'checkBoundsAreSatisfied' to ConstraintsUtil
This commit is contained in:
+1
-16
@@ -123,7 +123,7 @@ public class ConstraintsSystemImpl implements ConstraintsSystem {
|
||||
addConstraint(ConstraintKind.SUPER_TYPE, subjectType, constrainingType, constraintPosition);
|
||||
}
|
||||
|
||||
public void addConstraint(@NotNull ConstraintKind constraintKind, @NotNull JetType subjectType, @NotNull JetType constrainingType,
|
||||
private void addConstraint(@NotNull ConstraintKind constraintKind, @NotNull JetType subjectType, @NotNull JetType constrainingType,
|
||||
@NotNull ConstraintPosition constraintPosition) {
|
||||
if (subjectType == DONT_CARE || constrainingType == DONT_CARE || subjectType == TypeUtils.NO_EXPECTED_TYPE
|
||||
|| constrainingType == TypeUtils.NO_EXPECTED_TYPE) {
|
||||
@@ -234,19 +234,4 @@ public class ConstraintsSystemImpl implements ConstraintsSystem {
|
||||
public TypeSubstitutor getResultingSubstitutor() {
|
||||
return resultingSubstitutor;
|
||||
}
|
||||
|
||||
public boolean upperBoundsAreSatisfied() {
|
||||
for (TypeParameterDescriptor typeParameter : typeParameterConstraints.keySet()) {
|
||||
JetType type = ConstraintsUtil.getValue(getTypeConstraints(typeParameter));
|
||||
JetType upperBound = typeParameter.getUpperBoundsAsType();
|
||||
JetType substitute = getResultingSubstitutor().substitute(upperBound, Variance.INVARIANT);
|
||||
|
||||
if (type != null) {
|
||||
if (substitute == null || !JetTypeChecker.INSTANCE.isSubtypeOf(type, substitute)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+15
@@ -150,4 +150,19 @@ public class ConstraintsUtil {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean checkBoundsAreSatisfied(ConstraintsSystem constraintsSystem) {
|
||||
for (TypeParameterDescriptor typeVariable : constraintsSystem.getTypeVariables()) {
|
||||
JetType type = getValue(constraintsSystem.getTypeConstraints(typeVariable));
|
||||
JetType upperBound = typeVariable.getUpperBoundsAsType();
|
||||
JetType substitutedType = constraintsSystem.getResultingSubstitutor().substitute(upperBound, Variance.INVARIANT);
|
||||
|
||||
if (type != null) {
|
||||
if (substitutedType == null || !JetTypeChecker.INSTANCE.isSubtypeOf(type, substitutedType)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -232,20 +232,20 @@ public class ExpressionTypingUtils {
|
||||
@NotNull JetType receiverType,
|
||||
@NotNull CallableDescriptor receiverArgument
|
||||
) {
|
||||
ConstraintsSystemImpl constraintsBuilder = new ConstraintsSystemImpl();
|
||||
ConstraintsSystem constraintsSystem = new ConstraintsSystemImpl();
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : receiverArgument.getTypeParameters()) {
|
||||
constraintsBuilder.registerTypeVariable(typeParameterDescriptor, Variance.INVARIANT);
|
||||
constraintsSystem.registerTypeVariable(typeParameterDescriptor, Variance.INVARIANT);
|
||||
}
|
||||
|
||||
ReceiverDescriptor receiverParameter = receiverArgument.getReceiverParameter();
|
||||
if (expectedReceiver.exists() && receiverParameter.exists()) {
|
||||
constraintsBuilder.addSubtypingConstraint(receiverType, receiverParameter.getType(), ConstraintPosition.RECEIVER_POSITION);
|
||||
constraintsSystem.addSubtypingConstraint(receiverType, receiverParameter.getType(), ConstraintPosition.RECEIVER_POSITION);
|
||||
}
|
||||
else if (expectedReceiver.exists() || receiverParameter.exists()) {
|
||||
// Only one of receivers exist
|
||||
return false;
|
||||
}
|
||||
|
||||
return constraintsBuilder.isSuccessful() && constraintsBuilder.upperBoundsAreSatisfied();
|
||||
return constraintsSystem.isSuccessful() && ConstraintsUtil.checkBoundsAreSatisfied(constraintsSystem);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user