added 'getCurrentSubstitutor' to ConstraintSystem

which returns DON_CARE type projection for unknown type parameters
This commit is contained in:
Svetlana Isakova
2012-07-18 19:58:35 +04:00
parent e3d2b013da
commit b567700545
3 changed files with 24 additions and 3 deletions
@@ -350,7 +350,7 @@ public class CallResolver {
for (ValueArgument valueArgument : resolvedValueArgument.getArguments()) { for (ValueArgument valueArgument : resolvedValueArgument.getArguments()) {
if (!JetPsiUtil.isFunctionLiteralWithoutDeclaredParameterTypes(valueArgument.getArgumentExpression())) continue; if (!JetPsiUtil.isFunctionLiteralWithoutDeclaredParameterTypes(valueArgument.getArgumentExpression())) continue;
addConstraintForValueArgument(valueArgument, valueParameterDescriptor, constraintsSystem.getResultingSubstitutor(), addConstraintForValueArgument(valueArgument, valueParameterDescriptor, constraintsSystem.getCurrentSubstitutor(),
constraintsSystem, context); constraintsSystem, context);
} }
} }
@@ -121,4 +121,11 @@ public interface ConstraintsSystem {
*/ */
@NotNull @NotNull
TypeSubstitutor getResultingSubstitutor(); TypeSubstitutor getResultingSubstitutor();
/**
* Returns a current result of solving the constraint system (mapping from the type variable to the resulting type projection).
* If there is no information for type parameter, returns type projection for DONT_CARE type.
*/
@NotNull
TypeSubstitutor getCurrentSubstitutor();
} }
@@ -39,10 +39,16 @@ public class ConstraintsSystemImpl implements ConstraintsSystem {
private final Map<TypeParameterDescriptor, TypeConstraintsImpl> typeParameterConstraints = Maps.newLinkedHashMap(); private final Map<TypeParameterDescriptor, TypeConstraintsImpl> typeParameterConstraints = Maps.newLinkedHashMap();
private final Set<ConstraintPosition> errorConstraintPositions = Sets.newHashSet(); private final Set<ConstraintPosition> errorConstraintPositions = Sets.newHashSet();
private final TypeSubstitutor resultingSubstitutor; private final TypeSubstitutor resultingSubstitutor;
private final TypeSubstitutor currentSubstitutor;
private boolean hasErrorInConstrainingTypes; private boolean hasErrorInConstrainingTypes;
public ConstraintsSystemImpl() { public ConstraintsSystemImpl() {
this.resultingSubstitutor = TypeSubstitutor.create(new TypeSubstitution() { this.resultingSubstitutor = createTypeSubstitutorWithDefaultForUnknownTypeParameter(null);
this.currentSubstitutor = createTypeSubstitutorWithDefaultForUnknownTypeParameter(new TypeProjection(DONT_CARE));
}
private TypeSubstitutor createTypeSubstitutorWithDefaultForUnknownTypeParameter(@Nullable final TypeProjection defaultTypeProjection) {
return TypeSubstitutor.create(new TypeSubstitution() {
@Override @Override
public TypeProjection get(TypeConstructor key) { public TypeProjection get(TypeConstructor key) {
DeclarationDescriptor declarationDescriptor = key.getDeclarationDescriptor(); DeclarationDescriptor declarationDescriptor = key.getDeclarationDescriptor();
@@ -54,7 +60,9 @@ public class ConstraintsSystemImpl implements ConstraintsSystem {
DONT_CARE.getConstructor()))) { DONT_CARE.getConstructor()))) {
return new TypeProjection(value); return new TypeProjection(value);
} }
return new TypeProjection(DONT_CARE); if (typeParameterConstraints.containsKey(descriptor)) {
return defaultTypeProjection;
}
} }
return null; return null;
} }
@@ -231,4 +239,10 @@ public class ConstraintsSystemImpl implements ConstraintsSystem {
public TypeSubstitutor getResultingSubstitutor() { public TypeSubstitutor getResultingSubstitutor() {
return resultingSubstitutor; return resultingSubstitutor;
} }
@NotNull
@Override
public TypeSubstitutor getCurrentSubstitutor() {
return currentSubstitutor;
}
} }