From 35ebbab733f0493f914882ad104caeec04392a07 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 29 Sep 2014 18:29:08 +0400 Subject: [PATCH] Fixed smart completion not working when parameter has default value --- .../jet/plugin/completion/ExpectedInfos.kt | 2 +- .../completion/smart/ParameterWithDefaultValue.kt | 7 +++++++ .../JvmSmartCompletionTestGenerated.java | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 idea/testData/completion/smart/ParameterWithDefaultValue.kt diff --git a/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt b/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt index 0fdfbaafcf6..141687e30e5 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt @@ -167,7 +167,7 @@ class ExpectedInfos(val bindingContext: BindingContext, val resolveSession: Reso val expectedInfos = HashSet() for (candidate: ResolvedCall in results.getAllCandidates()!!) { // consider only candidates with more arguments than in the truncated call and with all arguments before the current one matched - if (candidate.noErrorsInValueArguments() && (isFunctionLiteralArgument || candidate.hasUnmappedParameters())) { + if (candidate.noErrorsInValueArguments() && (candidate.getCandidateDescriptor().getValueParameters().size > argumentIndex || isFunctionLiteralArgument)) { val descriptor = candidate.getResultingDescriptor() if (!Visibilities.isVisible(descriptor, resolutionScope.getContainingDeclaration())) continue diff --git a/idea/testData/completion/smart/ParameterWithDefaultValue.kt b/idea/testData/completion/smart/ParameterWithDefaultValue.kt new file mode 100644 index 00000000000..fa474cb8e7d --- /dev/null +++ b/idea/testData/completion/smart/ParameterWithDefaultValue.kt @@ -0,0 +1,7 @@ +fun foo(p1: String, p2: String = "") { } + +fun bar(s: String) { + foo("", ) +} + +// EXIST: s diff --git a/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java index 8258d904a8f..5e5de4b209b 100644 --- a/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java @@ -17,9 +17,13 @@ package org.jetbrains.jet.completion; import com.intellij.testFramework.TestDataPath; -import org.jetbrains.jet.JetTestUtils; -import org.jetbrains.jet.test.TestMetadata; +import junit.framework.Test; +import junit.framework.TestSuite; import org.junit.runner.RunWith; +import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.test.InnerTestClasses; +import org.jetbrains.jet.test.TestMetadata; +import org.jetbrains.jet.JUnit3RunnerWithInners; import java.io.File; import java.util.regex.Pattern; @@ -604,6 +608,12 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT doTest(fileName); } + @TestMetadata("ParameterWithDefaultValue.kt") + public void testParameterWithDefaultValue() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smart/ParameterWithDefaultValue.kt"); + doTest(fileName); + } + @TestMetadata("PrivateConstructorForAbstract.kt") public void testPrivateConstructorForAbstract() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smart/PrivateConstructorForAbstract.kt");