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 7adb7669bb6..a3afe1cecfd 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 @@ -320,7 +320,7 @@ public class CallResolver { Set> failed = Sets.newLinkedHashSet(); for (ResolvedCall call : resultsWithIncompleteTypeInference.getResultingCalls()) { if (!(call instanceof ResolvedCallImpl)) continue; - ResolvedCallImpl resolvedCall = ((ResolvedCallImpl) call).copy(context); + ResolvedCallImpl resolvedCall = CallResolverUtil.copy((ResolvedCallImpl) call, context); if (!resolvedCall.hasUnknownTypeParameters()) { if (resolvedCall.getStatus().isSuccess()) { successful.add(resolvedCall); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolverUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolverUtil.java new file mode 100644 index 00000000000..21ec8729a64 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolverUtil.java @@ -0,0 +1,60 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.lang.resolve.calls; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.descriptors.CallableDescriptor; +import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; +import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; +import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace; +import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem; +import org.jetbrains.jet.lang.types.JetType; + +import java.util.Map; + +public class CallResolverUtil { + + public static ResolvedCallImpl copy(@NotNull ResolvedCallImpl call, @NotNull ResolutionContext context) { + ResolutionCandidate candidate = ResolutionCandidate.create(call.getCandidateDescriptor(), call.getThisObject(), + call.getReceiverArgument(), call.getExplicitReceiverKind(), + call.isSafeCall()); + + TemporaryBindingTrace trace = TemporaryBindingTrace.create(context.trace, call.getTrace().toString() + "(copy)"); + ResolvedCallImpl copy = ResolvedCallImpl.create(candidate, trace); + + call.getTrace().addAllMyDataTo(trace); + trace.record(BindingContext.RESOLVED_CALL, context.call.getCalleeExpression(), copy); + + if (call.isDirty()) { + copy.argumentHasNoType(); + } + copy.setHasUnknownTypeParameters(call.hasUnknownTypeParameters()); + ConstraintSystem constraintSystem = call.getConstraintSystem(); + if (constraintSystem != null) { + copy.setConstraintSystem(constraintSystem.copy()); + } + for (Map.Entry entry : call.getTypeArguments().entrySet()) { + copy.recordTypeArgument(entry.getKey(), entry.getValue()); + } + for (Map.Entry entry : call.getValueArguments().entrySet()) { + copy.recordValueArgument(entry.getKey(), entry.getValue()); + } + return copy; + } + +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolvedCallImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolvedCallImpl.java index 4b646eafb98..6405e2f18cc 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolvedCallImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolvedCallImpl.java @@ -57,7 +57,7 @@ public class ResolvedCallImpl implements ResolvedC @NotNull public static ResolvedCallImpl create(@NotNull ResolutionCandidate candidate, @NotNull DelegatingBindingTrace trace) { - return new ResolvedCallImpl(candidate.getDescriptor(), candidate.getThisObject(), candidate.getReceiverArgument(), candidate.getExplicitReceiverKind(), candidate.isSafeCall(), trace); + return new ResolvedCallImpl(candidate, trace); } private final D candidateDescriptor; @@ -76,19 +76,12 @@ public class ResolvedCallImpl implements ResolvedC private boolean hasUnknownTypeParameters = false; private ConstraintSystem constraintSystem = null; - private ResolvedCallImpl( - @NotNull D candidateDescriptor, - @NotNull ReceiverDescriptor thisObject, - @NotNull ReceiverDescriptor receiverArgument, - @NotNull ExplicitReceiverKind explicitReceiverKind, - boolean isSafeCall, - @NotNull DelegatingBindingTrace trace - ) { - this.candidateDescriptor = candidateDescriptor; - this.thisObject = thisObject; - this.receiverArgument = receiverArgument; - this.explicitReceiverKind = explicitReceiverKind; - this.isSafeCall = isSafeCall; + private ResolvedCallImpl(@NotNull ResolutionCandidate candidate, @NotNull DelegatingBindingTrace trace) { + this.candidateDescriptor = candidate.getDescriptor(); + this.thisObject = candidate.getThisObject(); + this.receiverArgument = candidate.getReceiverArgument(); + this.explicitReceiverKind = candidate.getExplicitReceiverKind(); + this.isSafeCall = candidate.isSafeCall(); this.trace = trace; } @@ -237,23 +230,4 @@ public class ResolvedCallImpl implements ResolvedC public boolean isSafeCall() { return isSafeCall; } - - public ResolvedCallImpl copy(@NotNull ResolutionContext context) { - ResolvedCallImpl resolvedCall = new ResolvedCallImpl( - candidateDescriptor, thisObject, receiverArgument, explicitReceiverKind, isSafeCall, - TemporaryBindingTrace.create(context.trace, this.trace + "(copy)")); - this.trace.addAllMyDataTo(resolvedCall.trace); - resolvedCall.trace.record(BindingContext.RESOLVED_CALL, context.call.getCalleeExpression(), resolvedCall); - - resolvedCall.someArgumentHasNoType = this.someArgumentHasNoType; - resolvedCall.hasUnknownTypeParameters = this.hasUnknownTypeParameters; - if (constraintSystem != null) { - resolvedCall.constraintSystem = this.constraintSystem.copy(); - } - resolvedCall.typeArguments.putAll(this.typeArguments); - resolvedCall.valueArguments.putAll(this.valueArguments); - resolvedCall.autoCasts.putAll(this.autoCasts); - assert this.resultingDescriptor == null; - return resolvedCall; - } }