From 3649e61c2fb7f943bf71771a7bc6fbda8763f600 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Thu, 24 Jan 2019 14:42:52 +0900 Subject: [PATCH] Boolean literal arguments: do not report for varargs parameters #KT-29469 Fixed --- .../idea/inspections/BooleanLiteralArgumentInspection.kt | 3 +-- .../kotlin/idea/intentions/AddNameToArgumentIntention.kt | 2 +- .../inspectionsLocal/booleanLiteralArgument/vararg.kt | 6 ++++++ .../idea/inspections/LocalInspectionTestGenerated.java | 5 +++++ 4 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 idea/testData/inspectionsLocal/booleanLiteralArgument/vararg.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/BooleanLiteralArgumentInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/BooleanLiteralArgumentInspection.kt index 8be30a0dce3..bb5aebdb787 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/BooleanLiteralArgumentInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/BooleanLiteralArgumentInspection.kt @@ -16,7 +16,6 @@ import com.intellij.openapi.project.Project import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.diagnostics.Severity import org.jetbrains.kotlin.idea.caches.resolve.analyze -import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall import org.jetbrains.kotlin.idea.intentions.AddNameToArgumentIntention import org.jetbrains.kotlin.psi.KtCallExpression import org.jetbrains.kotlin.psi.KtConstantExpression @@ -38,7 +37,7 @@ class BooleanLiteralArgumentInspection( if (valueArguments.takeLastWhile { it != argument }.any { !it.isNamed() }) return if (argumentExpression.analyze().diagnostics.forElement(argumentExpression).any { it.severity == Severity.ERROR }) return - if (call.resolveToCall()?.resultingDescriptor?.hasStableParameterNames() != true) return + if (AddNameToArgumentIntention.detectNameToAdd(argument) == null) return val hasPreviousUnnamedBoolean = valueArguments.asSequence().windowed(size = 2, step = 1).any { (prev, next) -> next == argument && !prev.isNamed() && diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt index ad6234b2239..c9acc8438bb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt @@ -68,7 +68,7 @@ class AddNameToArgumentIntention : SelfTargetingIntention( return true } - private fun detectNameToAdd(argument: KtValueArgument): Name? { + fun detectNameToAdd(argument: KtValueArgument): Name? { if (argument.isNamed()) return null if (argument is KtLambdaArgument) return null diff --git a/idea/testData/inspectionsLocal/booleanLiteralArgument/vararg.kt b/idea/testData/inspectionsLocal/booleanLiteralArgument/vararg.kt new file mode 100644 index 00000000000..a04279549b8 --- /dev/null +++ b/idea/testData/inspectionsLocal/booleanLiteralArgument/vararg.kt @@ -0,0 +1,6 @@ +// PROBLEM: none +fun foo(vararg b: Boolean) {} + +fun test() { + foo(true, true, true) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index f6e48ba3f81..8570c73a1f7 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -113,6 +113,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { public void testJavaMethod() throws Exception { runTest("idea/testData/inspectionsLocal/booleanLiteralArgument/javaMethod.kt"); } + + @TestMetadata("vararg.kt") + public void testVararg() throws Exception { + runTest("idea/testData/inspectionsLocal/booleanLiteralArgument/vararg.kt"); + } } @TestMetadata("idea/testData/inspectionsLocal/branched")