diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java index b0eba8c7826..0d4a5224579 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java @@ -454,16 +454,17 @@ public class CandidateResolver { JetExpression expression = argument.getArgumentExpression(); JetExpression keyExpression = getDeferredComputationKeyExpression(expression); - markResultingCallAsCompleted(context, keyExpression); CallCandidateResolutionContext storedContextForArgument = context.resolutionResultsCache.getDeferredComputation(keyExpression); - if (storedContextForArgument != null) { - completeNestedCallsForNotResolvedInvocation(storedContextForArgument); - CallCandidateResolutionContext newContext = storedContextForArgument.replaceBindingTrace(context.trace); - completeUnmappedArguments(newContext, storedContextForArgument.candidateCall.getUnmappedArguments()); - argumentTypeResolver.checkTypesForFunctionArgumentsWithNoCallee(newContext.replaceContextDependency(INDEPENDENT)); - } + if (storedContextForArgument == null) continue; + if (storedContextForArgument.candidateCall.isCompleted()) continue; + + CallCandidateResolutionContext newContext = + storedContextForArgument.replaceBindingTrace(context.trace).replaceContextDependency(INDEPENDENT); + completeTypeInferenceDependentOnExpectedTypeForCall(newContext, true); + + markResultingCallAsCompleted(context, keyExpression); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/util/resolvedCallUtil.kt b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/util/resolvedCallUtil.kt new file mode 100644 index 00000000000..778c0a4836b --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/util/resolvedCallUtil.kt @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2014 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.util + +import org.jetbrains.jet.lang.descriptors.CallableDescriptor +import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall +import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults +import org.jetbrains.jet.lang.resolve.calls.model.ArgumentUnmapped +import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument +import org.jetbrains.jet.lang.resolve.calls.model.ArgumentMapping +import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor + +fun ResolvedCall.noErrorsInValueArguments(): Boolean { + return getCall().getValueArguments().all { argument -> !getArgumentMapping(argument!!).isError() } +} + +fun ResolvedCall.hasUnmappedArguments(): Boolean { + return getCall().getValueArguments().any { argument -> getArgumentMapping(argument!!) == ArgumentUnmapped } +} + +fun ResolvedCall.hasUnmappedParameters(): Boolean { + val parameterToArgumentMap = getValueArguments() + return !parameterToArgumentMap.keySet().containsAll(getResultingDescriptor().getValueParameters()) +} + +fun ResolvedCall.hasErrorOnParameter(parameter: ValueParameterDescriptor): Boolean { + val resolvedValueArgument = getValueArguments()[parameter] + if (resolvedValueArgument == null) return true + + return resolvedValueArgument.getArguments().any { argument -> getArgumentMapping(argument).isError() } +} diff --git a/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveNoInfoForParameter.kt b/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveNoInfoForParameter.kt index 41553b5f207..1cacf692c67 100644 --- a/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveNoInfoForParameter.kt +++ b/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveNoInfoForParameter.kt @@ -4,7 +4,7 @@ fun f(i: Int, c: Collection) fun f(a: Any, l: List): Collection {throw Exception()} fun test(l: List) { - f(1, emptyList()) + f(1, emptyList()) } fun emptyList(): List {throw Exception()} diff --git a/compiler/testData/diagnostics/tests/resolve/nestedCalls/completeTypeInferenceForNestedInNoneApplicable.kt b/compiler/testData/diagnostics/tests/resolve/nestedCalls/completeTypeInferenceForNestedInNoneApplicable.kt new file mode 100644 index 00000000000..4a569a2702a --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/nestedCalls/completeTypeInferenceForNestedInNoneApplicable.kt @@ -0,0 +1,10 @@ +package h + +fun foo(i: Int) = i +fun foo(s: String) = s + +fun test() { + foo(emptyList()) +} + +fun emptyList(): List {throw Exception()} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index d3e0bb327aa..589e5dcd418 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -6290,6 +6290,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest("compiler/testData/diagnostics/tests/resolve/nestedCalls/analyzeUnmappedArguments.kt"); } + @TestMetadata("completeTypeInferenceForNestedInNoneApplicable.kt") + public void testCompleteTypeInferenceForNestedInNoneApplicable() throws Exception { + doTest("compiler/testData/diagnostics/tests/resolve/nestedCalls/completeTypeInferenceForNestedInNoneApplicable.kt"); + } + @TestMetadata("completeUnmappedArguments.kt") public void testCompleteUnmappedArguments() throws Exception { doTest("compiler/testData/diagnostics/tests/resolve/nestedCalls/completeUnmappedArguments.kt"); diff --git a/idea/src/org/jetbrains/jet/plugin/completion/smart/SmartCompetionUtil.kt b/idea/src/org/jetbrains/jet/plugin/completion/smart/SmartCompetionUtil.kt new file mode 100644 index 00000000000..1a427f686d7 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/completion/smart/SmartCompetionUtil.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2014 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.plugin.completion.smart + +import org.jetbrains.jet.lang.descriptors.CallableDescriptor +import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults +import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall +import org.jetbrains.jet.lang.resolve.calls.util.noErrorsInValueArguments +import org.jetbrains.jet.lang.resolve.calls.util.hasUnmappedParameters + + +fun OverloadResolutionResults.getCandidatesForCompletion(): Collection> { + return getAllCandidates()!!.filter { resolvedCall -> + resolvedCall.noErrorsInValueArguments() && resolvedCall.hasUnmappedParameters() + } +}