diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java index 097aac13dd0..c1c05d5edea 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java @@ -350,7 +350,7 @@ public class CallResolver { for (ValueArgument valueArgument : resolvedValueArgument.getArguments()) { if (!JetPsiUtil.isFunctionLiteralWithoutDeclaredParameterTypes(valueArgument.getArgumentExpression())) continue; - addConstraintForValueArgument(valueArgument, valueParameterDescriptor, constraintsSystem.getResultingSubstitutor(), + addConstraintForValueArgument(valueArgument, valueParameterDescriptor, constraintsSystem.getCurrentSubstitutor(), constraintsSystem, context); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystem.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystem.java index 6806097fdd9..1eb876d3ab2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystem.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystem.java @@ -121,4 +121,11 @@ public interface ConstraintsSystem { */ @NotNull 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(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystemImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystemImpl.java index e358050b96b..c308704061f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystemImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintsSystemImpl.java @@ -39,10 +39,16 @@ public class ConstraintsSystemImpl implements ConstraintsSystem { private final Map typeParameterConstraints = Maps.newLinkedHashMap(); private final Set errorConstraintPositions = Sets.newHashSet(); private final TypeSubstitutor resultingSubstitutor; + private final TypeSubstitutor currentSubstitutor; private boolean hasErrorInConstrainingTypes; 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 public TypeProjection get(TypeConstructor key) { DeclarationDescriptor declarationDescriptor = key.getDeclarationDescriptor(); @@ -54,7 +60,9 @@ public class ConstraintsSystemImpl implements ConstraintsSystem { DONT_CARE.getConstructor()))) { return new TypeProjection(value); } - return new TypeProjection(DONT_CARE); + if (typeParameterConstraints.containsKey(descriptor)) { + return defaultTypeProjection; + } } return null; } @@ -231,4 +239,10 @@ public class ConstraintsSystemImpl implements ConstraintsSystem { public TypeSubstitutor getResultingSubstitutor() { return resultingSubstitutor; } + + @NotNull + @Override + public TypeSubstitutor getCurrentSubstitutor() { + return currentSubstitutor; + } }