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 fe11d3cf2da..baa2e099bc0 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 @@ -16,6 +16,7 @@ package org.jetbrains.jet.lang.resolve.calls; +import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -689,7 +690,7 @@ public class CallResolver { private ResolutionStatus inferTypeArguments(CallResolutionContext context) { ResolvedCallImpl candidateCall = context.candidateCall; - D candidate = candidateCall.getCandidateDescriptor(); + final D candidate = candidateCall.getCandidateDescriptor(); ResolutionDebugInfo.Data debugInfo = context.trace.get(ResolutionDebugInfo.RESOLUTION_DEBUG_INFO, context.call.getCallElement()); @@ -741,12 +742,13 @@ public class CallResolver { ConstraintPosition.RECEIVER_POSITION); } - Map typeVariablesMap = Maps.newLinkedHashMap(); - for (TypeParameterDescriptor typeParameterDescriptor : candidate.getTypeParameters()) { - typeVariablesMap.put(candidateWithFreshVariables.getTypeParameters().get(typeParameterDescriptor.getIndex()), - typeParameterDescriptor); - } - ConstraintSystem constraintBuilderWithRightTypeParameters = constraintsSystem.replaceTypeVariables(typeVariablesMap); + ConstraintSystem constraintBuilderWithRightTypeParameters = constraintsSystem.replaceTypeVariables(new Function() { + @Override + public TypeParameterDescriptor apply(@Nullable TypeParameterDescriptor typeParameterDescriptor) { + assert typeParameterDescriptor != null; + return candidate.getTypeParameters().get(typeParameterDescriptor.getIndex()); + } + }); candidateCall.setConstraintSystem(constraintBuilderWithRightTypeParameters); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java index c91d7a5b86b..0151e20b868 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java @@ -16,6 +16,7 @@ package org.jetbrains.jet.lang.resolve.calls.inference; +import com.google.common.base.Function; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import org.jetbrains.annotations.NotNull; @@ -105,13 +106,13 @@ public class ConstraintSystemImpl implements ConstraintSystem { } @NotNull - public ConstraintSystemImpl replaceTypeVariables(@NotNull Map typeVariablesMap) { + public ConstraintSystem replaceTypeVariables(@NotNull Function typeVariablesMap) { ConstraintSystemImpl newConstraintSystem = new ConstraintSystemImpl(); for (Map.Entry entry : typeParameterConstraints.entrySet()) { TypeParameterDescriptor typeParameter = entry.getKey(); TypeConstraintsImpl typeConstraints = entry.getValue(); - TypeParameterDescriptor newTypeParameter = typeVariablesMap.get(typeParameter); + TypeParameterDescriptor newTypeParameter = typeVariablesMap.apply(typeParameter); assert newTypeParameter != null; newConstraintSystem.typeParameterConstraints.put(newTypeParameter, typeConstraints); }