From 1e8aad50b0b6f29e6a9a49172eee9564104e40fa Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Wed, 18 Jun 2025 21:35:34 +0200 Subject: [PATCH] [kotlin] support default parameter values in SameParameterValue inspection - if we provide the default parameter value in `FirKotlinUastResolveProviderService.getArgumentForParameter`, then the omitted argument would be counted as real value (was not the case for k1) ^KTIJ-34329 fixed GitOrigin-RevId: 161d994ff994175fa51a445e76dac091fae8b886 --- .../reference/RefMethodImpl.java | 1 - .../reference/RefParameterImpl.java | 2 +- .../sameParameterValue/receiver/src/Test.kt | 19 +++++++++++++++++++ ...nSameParameterValueGlobalInspectionTest.kt | 4 ++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java b/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java index 9e5655903c22..a155b9de379a 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java @@ -525,7 +525,6 @@ public sealed class RefMethodImpl extends RefJavaElementImpl implements RefMetho void updateParameterValues(@NotNull UCallExpression call, @Nullable PsiElement elementPlace) { LOG.assertTrue(isInitialized()); - if (call.getValueArguments().isEmpty()) return; if (isExternalOverride()) return; if (!getSuperMethods().isEmpty()) { diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefParameterImpl.java b/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefParameterImpl.java index 21fa5753f4f6..fb2a5dde6975 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefParameterImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/reference/RefParameterImpl.java @@ -110,7 +110,7 @@ public final class RefParameterImpl extends RefJavaElementImpl implements RefPar myActualValueTemplate = VALUE_IS_NOT_CONST; } - synchronized void updateTemplateValue(UExpression expression, @Nullable PsiElement accessPlace) { + synchronized void updateTemplateValue(@Nullable UExpression expression, @Nullable PsiElement accessPlace) { myUsageCount++; if (myActualValueTemplate == VALUE_IS_NOT_CONST) return; diff --git a/java/java-tests/testData/inspection/jvm/sameParameterValue/receiver/src/Test.kt b/java/java-tests/testData/inspection/jvm/sameParameterValue/receiver/src/Test.kt index 734cb8577bc1..0f52521640c0 100644 --- a/java/java-tests/testData/inspection/jvm/sameParameterValue/receiver/src/Test.kt +++ b/java/java-tests/testData/inspection/jvm/sameParameterValue/receiver/src/Test.kt @@ -6,3 +6,22 @@ private fun String.privateFunctionWithReceiverAndVarargs(vararg fields: Int) {} suspend fun String.publicSuspendFunction() = privateSuspendFunctionWithReceiverAndVarargs(1, 2, 3) suspend fun String.publicSuspendFunction2() = privateSuspendFunctionWithReceiverAndVarargs(1, 2, 3) private suspend fun String.privateSuspendFunctionWithReceiverAndVarargs(vararg fields: Int) {} + +interface Fixture {} +private suspend fun Fixture.resolveRuntimeClasspath(projectPath: String = "") {} + +public suspend fun main(f: Fixture) { + f.resolveRuntimeClasspath("F") + f.resolveRuntimeClasspath("F") + f.resolveRuntimeClasspath("F") + f.resolveRuntimeClasspath() +} + +private suspend fun Fixture.sameAsDefault(projectPath: String = "F") {} + +public suspend fun main(f: Fixture) { + f.sameAsDefault("F") + f.sameAsDefault("F") + f.sameAsDefault("F") + f.sameAsDefault() +} diff --git a/jvm/jvm-analysis-kotlin-tests-shared/testSrc/com/intellij/codeInspection/tests/kotlin/KotlinSameParameterValueGlobalInspectionTest.kt b/jvm/jvm-analysis-kotlin-tests-shared/testSrc/com/intellij/codeInspection/tests/kotlin/KotlinSameParameterValueGlobalInspectionTest.kt index f71539f6f164..3314f9682762 100644 --- a/jvm/jvm-analysis-kotlin-tests-shared/testSrc/com/intellij/codeInspection/tests/kotlin/KotlinSameParameterValueGlobalInspectionTest.kt +++ b/jvm/jvm-analysis-kotlin-tests-shared/testSrc/com/intellij/codeInspection/tests/kotlin/KotlinSameParameterValueGlobalInspectionTest.kt @@ -28,4 +28,8 @@ abstract class KotlinSameParameterValueGlobalInspectionTest : SameParameterValue fun testNegativeDouble() { doHighlightTest() } + + fun testReceiver() { + doHighlightTest() + } }