diff --git a/plugins/kotlin/fir/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinHighLevelFunctionParameterInfoHandler.kt b/plugins/kotlin/fir/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinHighLevelFunctionParameterInfoHandler.kt index f5ee737d8262..99cee337030a 100644 --- a/plugins/kotlin/fir/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinHighLevelFunctionParameterInfoHandler.kt +++ b/plugins/kotlin/fir/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinHighLevelFunctionParameterInfoHandler.kt @@ -49,7 +49,7 @@ class KotlinHighLevelLambdaParameterInfoHandler : override fun getArgumentListAllowedParentClasses() = setOf(KtLambdaArgument::class.java) - override fun getParameterIndex(context: UpdateParameterInfoContext, argumentList: KtLambdaArgument): Int { + override fun getCurrentArgumentIndex(context: UpdateParameterInfoContext, argumentList: KtLambdaArgument): Int { val size = (argumentList.parent as? KtCallElement)?.valueArguments?.size ?: 1 return size - 1 } @@ -131,8 +131,8 @@ abstract class KotlinHighLevelParameterInfoWithCallHandlerBase= currentArgumentIndex) break + val parameterForArgument = argumentMapping[argument] ?: continue + if (parameterForArgument == setValueParameter) continue + + val argumentType = argument.getKtType() ?: error("Argument should have a KtType") + val parameterType = parameterForArgument.annotatedType.type + if (argumentType.isNotSubTypeOf(parameterType)) { + hasTypeMismatchBeforeCurrent = true + break + } + } + // TODO: This should be changed when there are multiple candidates available; need to know which one the call is resolved to val isCallResolvedToCandidate = candidates.size == 1 @@ -201,13 +215,14 @@ abstract class KotlinHighLevelParameterInfoWithCallHandlerBase() val text = buildString { var namedMode = false @@ -363,7 +381,14 @@ abstract class KotlinHighLevelParameterInfoWithCallHandlerBase valueParameterCount) - // TODO: Also disable if not all arguments before the current are matched. Need to check this in updateParameterInfo() - // See UpdateInTyping.kt tests - val hasMismatchBeforeCurrent = false - - val isDisabled = tooManyArgs || hasMismatchBeforeCurrent + val isDisabled = tooManyArgs || hasTypeMismatchBeforeCurrent || hasUnmappedArgumentBeforeCurrent context.setupUIComponentPresentation( text, @@ -443,7 +471,8 @@ abstract class KotlinHighLevelParameterInfoWithCallHandlerBase, val valueParameterCount: Int, val parameterIndexToText: Map, - val isCallResolvedToCandidate: Boolean + val isCallResolvedToCandidate: Boolean, + val hasTypeMismatchBeforeCurrent: Boolean, ) data class CandidateInfo( diff --git a/plugins/kotlin/fir/test/org/jetbrains/kotlin/idea/fir/parameterInfo/FirParameterInfoTestGenerated.java b/plugins/kotlin/fir/test/org/jetbrains/kotlin/idea/fir/parameterInfo/FirParameterInfoTestGenerated.java index 7fb1e4af1d9b..17bea12e2cea 100644 --- a/plugins/kotlin/fir/test/org/jetbrains/kotlin/idea/fir/parameterInfo/FirParameterInfoTestGenerated.java +++ b/plugins/kotlin/fir/test/org/jetbrains/kotlin/idea/fir/parameterInfo/FirParameterInfoTestGenerated.java @@ -402,6 +402,36 @@ public abstract class FirParameterInfoTestGenerated extends AbstractFirParameter runTest("../idea/tests/testData/parameterInfo/functionCall/TypeInference.kt"); } + @TestMetadata("UnmappedAfterCurrent.kt") + public void testUnmappedAfterCurrent() throws Exception { + runTest("../idea/tests/testData/parameterInfo/functionCall/UnmappedAfterCurrent.kt"); + } + + @TestMetadata("UnmappedBeforeCurrent.kt") + public void testUnmappedBeforeCurrent() throws Exception { + runTest("../idea/tests/testData/parameterInfo/functionCall/UnmappedBeforeCurrent.kt"); + } + + @TestMetadata("UnmappedCurrent.kt") + public void testUnmappedCurrent() throws Exception { + runTest("../idea/tests/testData/parameterInfo/functionCall/UnmappedCurrent.kt"); + } + + @TestMetadata("UnresolvedAfterCurrent.kt") + public void testUnresolvedAfterCurrent() throws Exception { + runTest("../idea/tests/testData/parameterInfo/functionCall/UnresolvedAfterCurrent.kt"); + } + + @TestMetadata("UnresolvedBeforeCurrent.kt") + public void testUnresolvedBeforeCurrent() throws Exception { + runTest("../idea/tests/testData/parameterInfo/functionCall/UnresolvedBeforeCurrent.kt"); + } + + @TestMetadata("UnresolvedCurrent.kt") + public void testUnresolvedCurrent() throws Exception { + runTest("../idea/tests/testData/parameterInfo/functionCall/UnresolvedCurrent.kt"); + } + @TestMetadata("UpdateOnTyping.kt") public void testUpdateOnTyping() throws Exception { runTest("../idea/tests/testData/parameterInfo/functionCall/UpdateOnTyping.kt"); diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/parameterInfo/ParameterInfoTestGenerated.java b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/parameterInfo/ParameterInfoTestGenerated.java index 8de86222f8c3..e59b6ea335c3 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/parameterInfo/ParameterInfoTestGenerated.java +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/parameterInfo/ParameterInfoTestGenerated.java @@ -402,6 +402,36 @@ public abstract class ParameterInfoTestGenerated extends AbstractParameterInfoTe runTest("testData/parameterInfo/functionCall/TypeInference.kt"); } + @TestMetadata("UnmappedAfterCurrent.kt") + public void testUnmappedAfterCurrent() throws Exception { + runTest("testData/parameterInfo/functionCall/UnmappedAfterCurrent.kt"); + } + + @TestMetadata("UnmappedBeforeCurrent.kt") + public void testUnmappedBeforeCurrent() throws Exception { + runTest("testData/parameterInfo/functionCall/UnmappedBeforeCurrent.kt"); + } + + @TestMetadata("UnmappedCurrent.kt") + public void testUnmappedCurrent() throws Exception { + runTest("testData/parameterInfo/functionCall/UnmappedCurrent.kt"); + } + + @TestMetadata("UnresolvedAfterCurrent.kt") + public void testUnresolvedAfterCurrent() throws Exception { + runTest("testData/parameterInfo/functionCall/UnresolvedAfterCurrent.kt"); + } + + @TestMetadata("UnresolvedBeforeCurrent.kt") + public void testUnresolvedBeforeCurrent() throws Exception { + runTest("testData/parameterInfo/functionCall/UnresolvedBeforeCurrent.kt"); + } + + @TestMetadata("UnresolvedCurrent.kt") + public void testUnresolvedCurrent() throws Exception { + runTest("testData/parameterInfo/functionCall/UnresolvedCurrent.kt"); + } + @TestMetadata("UpdateOnTyping.kt") public void testUpdateOnTyping() throws Exception { runTest("testData/parameterInfo/functionCall/UpdateOnTyping.kt"); diff --git a/plugins/kotlin/idea/tests/testData/parameterInfo/arrayAccess/UpdateOnTypingSet.kt b/plugins/kotlin/idea/tests/testData/parameterInfo/arrayAccess/UpdateOnTypingSet.kt index f7e0fdb3d2d2..51211c7235d9 100644 --- a/plugins/kotlin/idea/tests/testData/parameterInfo/arrayAccess/UpdateOnTypingSet.kt +++ b/plugins/kotlin/idea/tests/testData/parameterInfo/arrayAccess/UpdateOnTypingSet.kt @@ -1,4 +1,3 @@ -// IGNORE_FIR class A { operator fun get(x: Int) {} operator fun set(x: String, y: Int, value: Int) {} diff --git a/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/LocalFunctionBug.kt b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/LocalFunctionBug.kt index aec6c8ba89dd..bdc7df75b9f2 100644 --- a/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/LocalFunctionBug.kt +++ b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/LocalFunctionBug.kt @@ -1,4 +1,3 @@ -// IGNORE_FIR fun foo() { fun fff(p: String, c: Char) {} diff --git a/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/NotGreen.kt b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/NotGreen.kt index bca07c182ec0..fbaeec0ec971 100644 --- a/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/NotGreen.kt +++ b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/NotGreen.kt @@ -1,3 +1,5 @@ +// IGNORE_FIR +// TODO: Fails because no argument mapping is available when there are multiple ambiguous candidates open class A(x: Int) { fun m(x: Int, y: Boolean) = 2 fun m(x: Int) = 1 diff --git a/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnmappedAfterCurrent.kt b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnmappedAfterCurrent.kt new file mode 100644 index 000000000000..f9531214b49c --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnmappedAfterCurrent.kt @@ -0,0 +1,8 @@ +fun m(x: Int, y: Boolean) = 2 + +fun d() { + m(y = false, unmapped = false) +} +/* +Text: ([y: Boolean], [x: Int]), Disabled: false, Strikeout: false, Green: true +*/ \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnmappedBeforeCurrent.kt b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnmappedBeforeCurrent.kt new file mode 100644 index 000000000000..004a0fc55124 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnmappedBeforeCurrent.kt @@ -0,0 +1,8 @@ +fun m(x: Int, y: Boolean) = 2 + +fun d() { + m(unmapped = 1, y = false) +} +/* +Text: ([y: Boolean], [x: Int]), Disabled: true, Strikeout: false, Green: true +*/ \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnmappedCurrent.kt b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnmappedCurrent.kt new file mode 100644 index 000000000000..7e10cb0f2f75 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnmappedCurrent.kt @@ -0,0 +1,8 @@ +fun m(x: Int, y: Boolean) = 2 + +fun d() { + m(y = false, unmapped = false) +} +/* +Text: ([y: Boolean], [x: Int]), Disabled: false, Strikeout: false, Green: true +*/ \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnresolvedAfterCurrent.kt b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnresolvedAfterCurrent.kt new file mode 100644 index 000000000000..b4167ed6952d --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnresolvedAfterCurrent.kt @@ -0,0 +1,8 @@ +fun m(x: Int, y: Boolean) = 2 + +fun d() { + m(1, unresolved) +} +/* +Text: (x: Int, y: Boolean), Disabled: false, Strikeout: false, Green: true +*/ \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnresolvedBeforeCurrent.kt b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnresolvedBeforeCurrent.kt new file mode 100644 index 000000000000..a4d9ee51a01a --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnresolvedBeforeCurrent.kt @@ -0,0 +1,8 @@ +fun m(x: Int, y: Boolean) = 2 + +fun d() { + m(unresolved, true) +} +/* +Text: (x: Int, y: Boolean), Disabled: false, Strikeout: false, Green: true +*/ \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnresolvedCurrent.kt b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnresolvedCurrent.kt new file mode 100644 index 000000000000..2c165d40adae --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UnresolvedCurrent.kt @@ -0,0 +1,8 @@ +fun m(x: Int, y: Boolean) = 2 + +fun d() { + m(1, unresolved) +} +/* +Text: (x: Int, y: Boolean), Disabled: false, Strikeout: false, Green: true +*/ \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UpdateOnTyping.kt b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UpdateOnTyping.kt index 0ef15fe61e28..c52db600b675 100644 --- a/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UpdateOnTyping.kt +++ b/plugins/kotlin/idea/tests/testData/parameterInfo/functionCall/UpdateOnTyping.kt @@ -1,4 +1,3 @@ -// IGNORE_FIR fun fff(p: String, c: Char) {} fun foo() {