diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java index 950460736c4..316f9bbe55f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java @@ -575,7 +575,8 @@ public class CallResolver { public Unit invoke() { TemporaryBindingTrace candidateTrace = TemporaryBindingTrace.create( task.trace, "trace to resolve candidate"); - Collection> contexts = callTransformer.createCallContexts(resolutionCandidate, task, candidateTrace); + Collection> contexts = + callTransformer.createCallContexts(resolutionCandidate, task, candidateTrace, CandidateResolveMode.FULLY); for (CallCandidateResolutionContext context : contexts) { candidateResolver.performResolutionForCandidateCall(context, task); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallTransformer.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallTransformer.java index c30606d5a0c..f87fb75d18d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallTransformer.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallTransformer.java @@ -31,6 +31,7 @@ import org.jetbrains.kotlin.resolve.DelegatingBindingTrace; import org.jetbrains.kotlin.resolve.TemporaryBindingTrace; import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext; import org.jetbrains.kotlin.resolve.calls.context.CallCandidateResolutionContext; +import org.jetbrains.kotlin.resolve.calls.context.CandidateResolveMode; import org.jetbrains.kotlin.resolve.calls.context.ContextDependency; import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall; import org.jetbrains.kotlin.resolve.calls.model.ResolvedCallImpl; @@ -73,10 +74,12 @@ public class CallTransformer { @NotNull public Collection> createCallContexts(@NotNull ResolutionCandidate candidate, @NotNull ResolutionTask task, - @NotNull TemporaryBindingTrace candidateTrace + @NotNull TemporaryBindingTrace candidateTrace, + @NotNull CandidateResolveMode candidateResolveMode ) { ResolvedCallImpl candidateCall = ResolvedCallImpl.create(candidate, candidateTrace, task.tracing, task.dataFlowInfoForArguments); - return Collections.singleton(CallCandidateResolutionContext.create(candidateCall, task, candidateTrace, task.tracing)); + return Collections.singleton(CallCandidateResolutionContext.create(candidateCall, task, candidateTrace, task.tracing, task.call, + ReceiverValue.NO_RECEIVER, candidateResolveMode)); } /** @@ -100,10 +103,12 @@ public class CallTransformer { @NotNull @Override public Collection> createCallContexts(@NotNull ResolutionCandidate candidate, - @NotNull ResolutionTask task, @NotNull TemporaryBindingTrace candidateTrace) { + @NotNull ResolutionTask task, @NotNull TemporaryBindingTrace candidateTrace, + @NotNull CandidateResolveMode candidateResolveMode + ) { if (candidate.getDescriptor() instanceof FunctionDescriptor) { - return super.createCallContexts(candidate, task, candidateTrace); + return super.createCallContexts(candidate, task, candidateTrace, candidateResolveMode); } assert candidate.getDescriptor() instanceof VariableDescriptor; @@ -120,11 +125,11 @@ public class CallTransformer { if (!hasReceiver) { CallCandidateResolutionContext context = CallCandidateResolutionContext.create( ResolvedCallImpl.create(variableCandidate, candidateTrace, task.tracing, task.dataFlowInfoForArguments), - task, candidateTrace, task.tracing, variableCall); + task, candidateTrace, task.tracing, variableCall, ReceiverValue.NO_RECEIVER, candidateResolveMode); return Collections.singleton(context); } CallCandidateResolutionContext contextWithReceiver = createContextWithChainedTrace( - variableCandidate, variableCall, candidateTrace, task, ReceiverValue.NO_RECEIVER); + variableCandidate, variableCall, candidateTrace, task, ReceiverValue.NO_RECEIVER, candidateResolveMode); Call variableCallWithoutReceiver = stripReceiver(variableCall); ResolutionCandidate candidateWithoutReceiver = ResolutionCandidate.create( @@ -135,18 +140,21 @@ public class CallTransformer { ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, null); CallCandidateResolutionContext contextWithoutReceiver = createContextWithChainedTrace( - candidateWithoutReceiver, variableCallWithoutReceiver, candidateTrace, task, variableCall.getExplicitReceiver()); + candidateWithoutReceiver, variableCallWithoutReceiver, candidateTrace, task, variableCall.getExplicitReceiver(), + candidateResolveMode); return Lists.newArrayList(contextWithReceiver, contextWithoutReceiver); } private CallCandidateResolutionContext createContextWithChainedTrace( @NotNull ResolutionCandidate candidate, @NotNull Call call, @NotNull TemporaryBindingTrace temporaryTrace, - @NotNull ResolutionTask task, @NotNull ReceiverValue receiverValue + @NotNull ResolutionTask task, @NotNull ReceiverValue receiverValue, + @NotNull CandidateResolveMode candidateResolveMode ) { ChainedTemporaryBindingTrace chainedTrace = ChainedTemporaryBindingTrace.create(temporaryTrace, "chained trace to resolve candidate", candidate); ResolvedCallImpl resolvedCall = ResolvedCallImpl.create(candidate, chainedTrace, task.tracing, task.dataFlowInfoForArguments); - return CallCandidateResolutionContext.create(resolvedCall, task, chainedTrace, task.tracing, call, receiverValue); + return CallCandidateResolutionContext.create(resolvedCall, task, chainedTrace, task.tracing, call, receiverValue, + candidateResolveMode); } private Call stripCallArguments(@NotNull Call call) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/CallCandidateResolutionContext.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/CallCandidateResolutionContext.java index c33ae1c6f91..afd630c4cee 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/CallCandidateResolutionContext.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/CallCandidateResolutionContext.java @@ -40,6 +40,8 @@ public final class CallCandidateResolutionContext public final TracingStrategy tracing; @NotNull public final ReceiverValue explicitExtensionReceiverForInvoke; + @NotNull + public final CandidateResolveMode candidateResolveMode; private CallCandidateResolutionContext( @NotNull MutableResolvedCall candidateCall, @@ -58,6 +60,7 @@ public final class CallCandidateResolutionContext @NotNull AdditionalTypeChecker additionalTypeChecker, @NotNull StatementFilter statementFilter, @NotNull ReceiverValue explicitExtensionReceiverForInvoke, + @NotNull CandidateResolveMode candidateResolveMode, boolean isAnnotationContext, boolean collectAllCandidates, boolean insideSafeCallChain @@ -68,11 +71,13 @@ public final class CallCandidateResolutionContext this.candidateCall = candidateCall; this.tracing = tracing; this.explicitExtensionReceiverForInvoke = explicitExtensionReceiverForInvoke; + this.candidateResolveMode = candidateResolveMode; } public static CallCandidateResolutionContext create( @NotNull MutableResolvedCall candidateCall, @NotNull CallResolutionContext context, @NotNull BindingTrace trace, - @NotNull TracingStrategy tracing, @NotNull Call call, @NotNull ReceiverValue explicitExtensionReceiverForInvoke + @NotNull TracingStrategy tracing, @NotNull Call call, @NotNull ReceiverValue explicitExtensionReceiverForInvoke, + @NotNull CandidateResolveMode candidateResolveMode ) { candidateCall.getDataFlowInfoForArguments().setInitialDataFlowInfo(context.dataFlowInfo); return new CallCandidateResolutionContext( @@ -80,20 +85,7 @@ public final class CallCandidateResolutionContext context.dataFlowInfo, context.contextDependency, context.checkArguments, context.resolutionResultsCache, context.dataFlowInfoForArguments, context.callChecker, context.symbolUsageValidator, context.additionalTypeChecker, context.statementFilter, explicitExtensionReceiverForInvoke, - context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain); - } - - public static CallCandidateResolutionContext create( - @NotNull MutableResolvedCall candidateCall, @NotNull CallResolutionContext context, @NotNull BindingTrace trace, - @NotNull TracingStrategy tracing, @NotNull Call call - ) { - return create(candidateCall, context, trace, tracing, call, ReceiverValue.NO_RECEIVER); - } - - public static CallCandidateResolutionContext create( - @NotNull MutableResolvedCall candidateCall, @NotNull CallResolutionContext context, @NotNull BindingTrace trace, - @NotNull TracingStrategy tracing) { - return create(candidateCall, context, trace, tracing, context.call); + candidateResolveMode, context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain); } @NotNull @@ -104,7 +96,7 @@ public final class CallCandidateResolutionContext candidateCall, tracing, context.trace, context.scope, context.call, context.expectedType, context.dataFlowInfo, context.contextDependency, context.checkArguments, context.resolutionResultsCache, context.dataFlowInfoForArguments, context.callChecker, context.symbolUsageValidator, context.additionalTypeChecker, context.statementFilter, - ReceiverValue.NO_RECEIVER, context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain); + ReceiverValue.NO_RECEIVER, CandidateResolveMode.FULLY, context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain); } @Override @@ -122,6 +114,6 @@ public final class CallCandidateResolutionContext return new CallCandidateResolutionContext( candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache, dataFlowInfoForArguments, callChecker, symbolUsageValidator, additionalTypeChecker, statementFilter, - explicitExtensionReceiverForInvoke, isAnnotationContext, collectAllCandidates, insideSafeCallChain); + explicitExtensionReceiverForInvoke, candidateResolveMode, isAnnotationContext, collectAllCandidates, insideSafeCallChain); } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/CandidateResolveMode.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/CandidateResolveMode.java new file mode 100644 index 00000000000..7e2ac6fb467 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/CandidateResolveMode.java @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2015 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.kotlin.resolve.calls.context; + +public enum CandidateResolveMode { + FULLY, + EXIT_ON_FIRST_ERROR +}