From 5d04fa3c2f0f046cc2649dab9f95fcfe61fd63e6 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 20 Jul 2016 19:53:04 +0300 Subject: [PATCH] Remove unreachable code in ResolutionResultsHandler --- .../resolve/calls/model/ResolvedCallImpl.java | 7 --- .../results/ResolutionResultsHandler.java | 49 ++++++++----------- 2 files changed, 20 insertions(+), 36 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallImpl.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallImpl.java index 3f466c0475b..7dd04ad9102 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallImpl.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallImpl.java @@ -47,13 +47,6 @@ import static org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus.UNKNOW public class ResolvedCallImpl implements MutableResolvedCall { private static final Logger LOG = Logger.getInstance(ResolvedCallImpl.class); - public static final Function, CallableDescriptor> MAP_TO_CANDIDATE = new Function, CallableDescriptor>() { - @Override - public CallableDescriptor fun(MutableResolvedCall resolvedCall) { - return resolvedCall.getCandidateDescriptor(); - } - }; - public static final Function, CallableDescriptor> MAP_TO_RESULT = new Function, CallableDescriptor>() { @Override public CallableDescriptor fun(MutableResolvedCall resolvedCall) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionResultsHandler.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionResultsHandler.java index 18f09740d48..b87074fdc68 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionResultsHandler.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionResultsHandler.java @@ -32,7 +32,6 @@ import java.util.Collection; import java.util.EnumSet; import java.util.Set; -import static org.jetbrains.kotlin.resolve.calls.model.ResolvedCallImpl.MAP_TO_CANDIDATE; import static org.jetbrains.kotlin.resolve.calls.model.ResolvedCallImpl.MAP_TO_RESULT; import static org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus.*; @@ -133,33 +132,27 @@ public class ResolutionResultsHandler { @NotNull Set> failedCandidates, @NotNull CheckArgumentTypesMode checkArgumentsMode ) { - if (failedCandidates.size() != 1) { - // This is needed when there are several overloads some of which are OK but for nullability of the receiver, - // and some are not OK at all. In this case we'd like to say "unsafe call" rather than "none applicable" - // Used to be: weak errors. Generalized for future extensions - for (EnumSet severityLevel : SEVERITY_LEVELS) { - Set> thisLevel = Sets.newLinkedHashSet(); - for (MutableResolvedCall candidate : failedCandidates) { - if (severityLevel.contains(candidate.getStatus())) { - thisLevel.add(candidate); - } - } - if (!thisLevel.isEmpty()) { - if (severityLevel.contains(ARGUMENTS_MAPPING_ERROR)) { - return recordFailedInfo(tracing, trace, thisLevel); - } - OverloadResolutionResultsImpl results = chooseAndReportMaximallySpecific(thisLevel, false, false, checkArgumentsMode); - return recordFailedInfo(tracing, trace, results.getResultingCalls()); - } - } - - assert false : "Should not be reachable, cause every status must belong to some level"; - - Set> noOverrides = OverrideResolver.filterOutOverridden(failedCandidates, MAP_TO_CANDIDATE); - return recordFailedInfo(tracing, trace, noOverrides); + if (failedCandidates.size() == 1) { + return recordFailedInfo(tracing, trace, failedCandidates); } - return recordFailedInfo(tracing, trace, failedCandidates); + for (EnumSet severityLevel : SEVERITY_LEVELS) { + Set> thisLevel = Sets.newLinkedHashSet(); + for (MutableResolvedCall candidate : failedCandidates) { + if (severityLevel.contains(candidate.getStatus())) { + thisLevel.add(candidate); + } + } + if (!thisLevel.isEmpty()) { + if (severityLevel.contains(ARGUMENTS_MAPPING_ERROR)) { + return recordFailedInfo(tracing, trace, thisLevel); + } + OverloadResolutionResultsImpl results = chooseAndReportMaximallySpecific(thisLevel, false, false, checkArgumentsMode); + return recordFailedInfo(tracing, trace, results.getResultingCalls()); + } + } + + throw new AssertionError("Should not be reachable, cause every status must belong to some level: " + failedCandidates); } @NotNull @@ -186,7 +179,7 @@ public class ResolutionResultsHandler { } @NotNull - public OverloadResolutionResultsImpl chooseAndReportMaximallySpecific( + private OverloadResolutionResultsImpl chooseAndReportMaximallySpecific( @NotNull Set> candidates, boolean discriminateGenerics, boolean isDebuggerContext, @@ -220,6 +213,4 @@ public class ResolutionResultsHandler { return OverloadResolutionResultsImpl.ambiguity(noOverrides); } - - }