rename replaceTypeVariables -> createNewConstraintSystemFromThis
This commit is contained in:
@@ -579,14 +579,15 @@ public class CandidateResolver {
|
|||||||
constraintSystem.addSubtypeConstraint(receiverType, receiverParameter.getType(), ConstraintPosition.RECEIVER_POSITION);
|
constraintSystem.addSubtypeConstraint(receiverType, receiverParameter.getType(), ConstraintPosition.RECEIVER_POSITION);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstraintSystem constraintSystemWithRightTypeParameters = constraintSystem.replaceTypeVariables(
|
// Restore type variables before alpha-conversion
|
||||||
|
ConstraintSystem constraintSystemWithRightTypeParameters = constraintSystem.substituteTypeVariables(
|
||||||
new Function<TypeParameterDescriptor, TypeParameterDescriptor>() {
|
new Function<TypeParameterDescriptor, TypeParameterDescriptor>() {
|
||||||
@Override
|
@Override
|
||||||
public TypeParameterDescriptor apply(@Nullable TypeParameterDescriptor typeParameterDescriptor) {
|
public TypeParameterDescriptor apply(@Nullable TypeParameterDescriptor typeParameterDescriptor) {
|
||||||
assert typeParameterDescriptor != null;
|
assert typeParameterDescriptor != null;
|
||||||
return candidate.getTypeParameters().get(typeParameterDescriptor.getIndex());
|
return candidate.getTypeParameters().get(typeParameterDescriptor.getIndex());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
candidateCall.setConstraintSystem(constraintSystemWithRightTypeParameters);
|
candidateCall.setConstraintSystem(constraintSystemWithRightTypeParameters);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+33
-35
@@ -39,7 +39,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition.EXPECTED_TYPE_POSITION;
|
|
||||||
import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl.ConstraintKind.EQUAL;
|
import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl.ConstraintKind.EQUAL;
|
||||||
import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl.ConstraintKind.SUB_TYPE;
|
import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl.ConstraintKind.SUB_TYPE;
|
||||||
import static org.jetbrains.jet.lang.resolve.calls.inference.TypeBoundsImpl.BoundKind.*;
|
import static org.jetbrains.jet.lang.resolve.calls.inference.TypeBoundsImpl.BoundKind.*;
|
||||||
@@ -73,8 +72,7 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
@Override
|
@Override
|
||||||
public boolean hasViolatedUpperBound() {
|
public boolean hasViolatedUpperBound() {
|
||||||
if (isSuccessful()) return false;
|
if (isSuccessful()) return false;
|
||||||
ConstraintSystem systemWithoutWeakConstraints = getSystemWithoutWeakConstraints();
|
return getSystemWithoutWeakConstraints().getStatus().isSuccessful();
|
||||||
return systemWithoutWeakConstraints.getStatus().isSuccessful();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -193,21 +191,22 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public ConstraintSystem copy() {
|
public ConstraintSystem copy() {
|
||||||
return replaceTypeVariables(Functions.<TypeParameterDescriptor>identity(),
|
return createNewConstraintSystemFromThis(Functions.<TypeParameterDescriptor>identity(),
|
||||||
new Function<TypeBoundsImpl, TypeBoundsImpl>() {
|
new Function<TypeBoundsImpl, TypeBoundsImpl>() {
|
||||||
@Override
|
@Override
|
||||||
public TypeBoundsImpl apply(TypeBoundsImpl typeBounds) {
|
public TypeBoundsImpl apply(TypeBoundsImpl typeBounds) {
|
||||||
return typeBounds.copy();
|
return typeBounds.copy();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Conditions.<ConstraintPosition>alwaysTrue());
|
Conditions.<ConstraintPosition>alwaysTrue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ConstraintSystem replaceTypeVariables(@NotNull Function<TypeParameterDescriptor, TypeParameterDescriptor> typeVariablesMap) {
|
public ConstraintSystem substituteTypeVariables(@NotNull Function<TypeParameterDescriptor, TypeParameterDescriptor> typeVariablesMap) {
|
||||||
return replaceTypeVariables(typeVariablesMap,
|
return createNewConstraintSystemFromThis(typeVariablesMap,
|
||||||
Functions.<TypeBoundsImpl>identity(),
|
// type bounds are proper types and don't contain other variables
|
||||||
Conditions.<ConstraintPosition>alwaysTrue());
|
Functions.<TypeBoundsImpl>identity(),
|
||||||
|
Conditions.<ConstraintPosition>alwaysTrue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -223,14 +222,14 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ConstraintSystem filterConstraints(@NotNull final Condition<ConstraintPosition> condition) {
|
public ConstraintSystem filterConstraints(@NotNull final Condition<ConstraintPosition> condition) {
|
||||||
return replaceTypeVariables(Functions.<TypeParameterDescriptor>identity(),
|
return createNewConstraintSystemFromThis(Functions.<TypeParameterDescriptor>identity(),
|
||||||
new Function<TypeBoundsImpl, TypeBoundsImpl>() {
|
new Function<TypeBoundsImpl, TypeBoundsImpl>() {
|
||||||
@Override
|
@Override
|
||||||
public TypeBoundsImpl apply(TypeBoundsImpl typeBounds) {
|
public TypeBoundsImpl apply(TypeBoundsImpl typeBounds) {
|
||||||
return typeBounds.filter(condition);
|
return typeBounds.filter(condition);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
condition);
|
condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -251,25 +250,24 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private ConstraintSystem replaceTypeVariables(
|
private ConstraintSystem createNewConstraintSystemFromThis(
|
||||||
@NotNull Function<TypeParameterDescriptor, TypeParameterDescriptor> typeVariablesMap,
|
@NotNull Function<TypeParameterDescriptor, TypeParameterDescriptor> substituteTypeVariable,
|
||||||
@NotNull Function<TypeBoundsImpl, TypeBoundsImpl> typeBoundsMap,
|
@NotNull Function<TypeBoundsImpl, TypeBoundsImpl> replaceTypeBounds,
|
||||||
@NotNull Condition<ConstraintPosition> constraintPositionCondition
|
@NotNull Condition<ConstraintPosition> filterConstraintPosition
|
||||||
|
|
||||||
) {
|
) {
|
||||||
ConstraintSystemImpl newConstraintSystem = new ConstraintSystemImpl();
|
ConstraintSystemImpl newSystem = new ConstraintSystemImpl();
|
||||||
for (Map.Entry<TypeParameterDescriptor, TypeBoundsImpl> entry : typeParameterBounds.entrySet()) {
|
for (Map.Entry<TypeParameterDescriptor, TypeBoundsImpl> entry : typeParameterBounds.entrySet()) {
|
||||||
TypeParameterDescriptor typeParameter = entry.getKey();
|
TypeParameterDescriptor typeParameter = entry.getKey();
|
||||||
TypeBoundsImpl typeBounds = entry.getValue();
|
TypeBoundsImpl typeBounds = entry.getValue();
|
||||||
|
|
||||||
TypeParameterDescriptor newTypeParameter = typeVariablesMap.apply(typeParameter);
|
TypeParameterDescriptor newTypeParameter = substituteTypeVariable.apply(typeParameter);
|
||||||
assert newTypeParameter != null;
|
assert newTypeParameter != null;
|
||||||
newConstraintSystem.typeParameterBounds.put(newTypeParameter, typeBoundsMap.apply(typeBounds));
|
newSystem.typeParameterBounds.put(newTypeParameter, replaceTypeBounds.apply(typeBounds));
|
||||||
}
|
}
|
||||||
newConstraintSystem.errorConstraintPositions.addAll(ContainerUtil.filter(errorConstraintPositions, constraintPositionCondition));
|
newSystem.errorConstraintPositions.addAll(ContainerUtil.filter(errorConstraintPositions, filterConstraintPosition));
|
||||||
//todo if 'constraintPositionCondition' is not trivial, it's incorrect to just copy 'hasErrorInConstrainingTypes'
|
//todo if 'filterConstraintPosition' is not trivial, it's incorrect to just copy 'hasErrorInConstrainingTypes'
|
||||||
newConstraintSystem.hasErrorInConstrainingTypes = hasErrorInConstrainingTypes;
|
newSystem.hasErrorInConstrainingTypes = hasErrorInConstrainingTypes;
|
||||||
return newConstraintSystem;
|
return newSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user