rename 'add subtype/supertype constraint' methods:
supertype constraint means constraining type is a supertype of subject type (not vice versa)
This commit is contained in:
@@ -374,8 +374,8 @@ public class CallResolver {
|
||||
}
|
||||
|
||||
ConstraintSystem constraintSystemWithoutExpectedTypeConstraint = constraintSystem.copy();
|
||||
constraintSystem.addSubtypingConstraint(descriptor.getReturnType(), context.expectedType,
|
||||
ConstraintPosition.EXPECTED_TYPE_POSITION);
|
||||
constraintSystem.addSupertypeConstraint(descriptor.getReturnType(), context.expectedType,
|
||||
ConstraintPosition.EXPECTED_TYPE_POSITION);
|
||||
|
||||
|
||||
if (!constraintSystem.isSuccessful()) {
|
||||
@@ -761,8 +761,8 @@ public class CallResolver {
|
||||
ReceiverDescriptor receiverArgument = candidateCall.getReceiverArgument();
|
||||
ReceiverDescriptor receiverParameter = candidateWithFreshVariables.getReceiverParameter();
|
||||
if (receiverArgument.exists() && receiverParameter.exists()) {
|
||||
constraintsSystem.addSupertypeConstraint(receiverParameter.getType(), receiverArgument.getType(),
|
||||
ConstraintPosition.RECEIVER_POSITION);
|
||||
constraintsSystem.addSubtypeConstraint(receiverParameter.getType(), receiverArgument.getType(),
|
||||
ConstraintPosition.RECEIVER_POSITION);
|
||||
}
|
||||
|
||||
ConstraintSystem constraintSystemWithRightTypeParameters = constraintsSystem.replaceTypeVariables(new Function<TypeParameterDescriptor, TypeParameterDescriptor>() {
|
||||
@@ -816,7 +816,7 @@ public class CallResolver {
|
||||
else {
|
||||
type = null;
|
||||
}
|
||||
constraintSystem.addSupertypeConstraint(effectiveExpectedType, type, ConstraintPosition.getValueParameterPosition(
|
||||
constraintSystem.addSubtypeConstraint(effectiveExpectedType, type, ConstraintPosition.getValueParameterPosition(
|
||||
valueParameterDescriptor.getIndex()));
|
||||
//todo no return
|
||||
if (isErrorType != null) {
|
||||
|
||||
+6
-6
@@ -42,22 +42,22 @@ public interface ConstraintSystem {
|
||||
Set<TypeParameterDescriptor> getTypeVariables();
|
||||
|
||||
/**
|
||||
* Adds a constraint that the subject type is a supertype of the constraining type.<p/>
|
||||
* Adds a constraint that the constraining type is a subtype of the subject type.<p/>
|
||||
* Asserts that only subject type may contain registered type variables. <p/>
|
||||
*
|
||||
* For example, for {@code "fun <T> id(t: T) {}"} to infer <tt>T</tt> in invocation <tt>"id(1)"</tt>
|
||||
* should be generated a constraint <tt>"T is a supertype of Int"</tt> where T is a subject type, and Int is a constraining type.
|
||||
* should be generated a constraint <tt>"Int is a subtype of T"</tt> where T is a subject type, and Int is a constraining type.
|
||||
*/
|
||||
void addSupertypeConstraint(@NotNull JetType subjectType, @Nullable JetType constrainingType, @NotNull ConstraintPosition constraintPosition);
|
||||
void addSubtypeConstraint(@NotNull JetType subjectType, @Nullable JetType constrainingType, @NotNull ConstraintPosition constraintPosition);
|
||||
|
||||
/**
|
||||
* Adds a constraint that subject type is a subtype of constraining type. <p/>
|
||||
* Adds a constraint that the constraining type is a supertype of the subject type. <p/>
|
||||
* Asserts that only subject type may contain registered type variables. <p/>
|
||||
*
|
||||
* For example, for {@code "fun <T> create() : T"} to infer <tt>T</tt> in invocation <tt>"val i: Int = create()"</tt>
|
||||
* should be generated a constraint <tt>"T is a subtype of Int"</tt> where T is a subject type, and Int is a constraining type.
|
||||
* should be generated a constraint <tt>"Int is a supertype of T"</tt> where T is a subject type, and Int is a constraining type.
|
||||
*/
|
||||
void addSubtypingConstraint(@NotNull JetType subjectType, @Nullable JetType constrainingType, @NotNull ConstraintPosition constraintPosition);
|
||||
void addSupertypeConstraint(@NotNull JetType subjectType, @Nullable JetType constrainingType, @NotNull ConstraintPosition constraintPosition);
|
||||
|
||||
/**
|
||||
* Returns <tt>true</tt> if constraint system has a solution (has no contradiction and has enough information to infer each registered type variable).
|
||||
|
||||
+10
-2
@@ -141,12 +141,20 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSubtypingConstraint(@NotNull JetType subjectType, @Nullable JetType constrainingType, @NotNull ConstraintPosition constraintPosition) {
|
||||
public void addSupertypeConstraint(
|
||||
@NotNull JetType subjectType,
|
||||
@Nullable JetType constrainingType,
|
||||
@NotNull ConstraintPosition constraintPosition
|
||||
) {
|
||||
addConstraint(SUB_TYPE, subjectType, constrainingType, constraintPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSupertypeConstraint(@NotNull JetType subjectType, @Nullable JetType constrainingType, @NotNull ConstraintPosition constraintPosition) {
|
||||
public void addSubtypeConstraint(
|
||||
@NotNull JetType subjectType,
|
||||
@Nullable JetType constrainingType,
|
||||
@NotNull ConstraintPosition constraintPosition
|
||||
) {
|
||||
addConstraint(SUPER_TYPE, subjectType, constrainingType, constraintPosition);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -252,7 +252,7 @@ public class ExpressionTypingUtils {
|
||||
}
|
||||
}
|
||||
|
||||
constraintSystem.addSupertypeConstraint(callReceiver.getType(), receiverType, ConstraintPosition.RECEIVER_POSITION);
|
||||
constraintSystem.addSubtypeConstraint(callReceiver.getType(), receiverType, ConstraintPosition.RECEIVER_POSITION);
|
||||
return constraintSystem.isSuccessful() && ConstraintsUtil.checkBoundsAreSatisfied(constraintSystem);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user