refactoring: register type variable together
not one by one
This commit is contained in:
@@ -562,10 +562,11 @@ public class CandidateResolver {
|
||||
// Thus, we replace the parameters of our descriptor with fresh objects (perform alpha-conversion)
|
||||
CallableDescriptor candidateWithFreshVariables = FunctionDescriptorUtil.alphaConvertTypeParameters(candidate);
|
||||
|
||||
|
||||
Map<TypeParameterDescriptor, Variance> typeVariables = Maps.newLinkedHashMap();
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : candidateWithFreshVariables.getTypeParameters()) {
|
||||
constraintSystem.registerTypeVariable(typeParameterDescriptor, Variance.INVARIANT); // TODO: variance of the occurrences
|
||||
typeVariables.put(typeParameterDescriptor, Variance.INVARIANT); // TODO: variance of the occurrences
|
||||
}
|
||||
constraintSystem.registerTypeVariables(typeVariables);
|
||||
|
||||
TypeSubstitutor substituteDontCare = ConstraintsUtil
|
||||
.makeConstantSubstitutor(candidateWithFreshVariables.getTypeParameters(), DONT_CARE);
|
||||
|
||||
+4
-1
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.lang.types.expressions;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -301,11 +302,13 @@ public class ExpressionTypingUtils {
|
||||
Set<Name> typeNamesInReceiver = collectUsedTypeNames(receiverParameter.getType());
|
||||
|
||||
ConstraintSystem constraintSystem = new ConstraintSystemImpl();
|
||||
Map<TypeParameterDescriptor, Variance> typeVariables = Maps.newLinkedHashMap();
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : callableDescriptor.getTypeParameters()) {
|
||||
if (typeNamesInReceiver.contains(typeParameterDescriptor.getName())) {
|
||||
constraintSystem.registerTypeVariable(typeParameterDescriptor, Variance.INVARIANT);
|
||||
typeVariables.put(typeParameterDescriptor, Variance.INVARIANT);
|
||||
}
|
||||
}
|
||||
constraintSystem.registerTypeVariables(typeVariables);
|
||||
|
||||
constraintSystem.addSubtypeConstraint(receiverType, receiverParameter.getType(), ConstraintPosition.RECEIVER_POSITION);
|
||||
return constraintSystem.getStatus().isSuccessful() && ConstraintsUtil.checkBoundsAreSatisfied(constraintSystem, true);
|
||||
|
||||
+3
-3
@@ -23,15 +23,15 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public interface ConstraintSystem {
|
||||
|
||||
/**
|
||||
* Registers a variable in a constraint system.
|
||||
* Registers variables in a constraint system.
|
||||
*/
|
||||
void registerTypeVariable(@NotNull TypeParameterDescriptor typeVariable, @NotNull Variance positionVariance);
|
||||
void registerTypeVariables(@NotNull Map<TypeParameterDescriptor, Variance> typeVariables);
|
||||
|
||||
/**
|
||||
* Returns a set of all registered type variables.
|
||||
|
||||
+6
-2
@@ -163,8 +163,12 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerTypeVariable(@NotNull TypeParameterDescriptor typeVariable, @NotNull Variance positionVariance) {
|
||||
typeParameterConstraints.put(typeVariable, new TypeConstraintsImpl(positionVariance));
|
||||
public void registerTypeVariables(@NotNull Map<TypeParameterDescriptor, Variance> typeVariables) {
|
||||
for (Map.Entry<TypeParameterDescriptor, Variance> entry : typeVariables.entrySet()) {
|
||||
TypeParameterDescriptor typeVariable = entry.getKey();
|
||||
Variance positionVariance = entry.getValue();
|
||||
typeParameterConstraints.put(typeVariable, new TypeConstraintsImpl(positionVariance));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -261,9 +261,7 @@ public class TypeUtils {
|
||||
processAllTypeParameters(withParameters, Variance.INVARIANT, processor);
|
||||
processAllTypeParameters(expected, Variance.INVARIANT, processor);
|
||||
ConstraintSystemImpl constraintSystem = new ConstraintSystemImpl();
|
||||
for (Map.Entry<TypeParameterDescriptor, Variance> entry : parameters.entrySet()) {
|
||||
constraintSystem.registerTypeVariable(entry.getKey(), entry.getValue());
|
||||
}
|
||||
constraintSystem.registerTypeVariables(parameters);
|
||||
constraintSystem.addSubtypeConstraint(withParameters, expected, ConstraintPosition.SPECIAL);
|
||||
|
||||
return constraintSystem.getStatus().isSuccessful();
|
||||
|
||||
Reference in New Issue
Block a user