From d00236d3663fa95d2876ad4a08fa3e3aecb933a5 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Tue, 25 Dec 2018 10:51:05 +0900 Subject: [PATCH] "Remove redundant backticks": Fix false positive for underscore #KT-28592 Fixed --- .../inspections/RemoveRedundantBackticksInspection.kt | 2 +- .../removeRedundantBackticks/underscore.kt | 8 ++++++++ .../idea/inspections/LocalInspectionTestGenerated.java | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 idea/testData/inspectionsLocal/removeRedundantBackticks/underscore.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantBackticksInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantBackticksInspection.kt index 524930a8fe1..1421db62e13 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantBackticksInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantBackticksInspection.kt @@ -46,7 +46,7 @@ class RemoveRedundantBackticksInspection : AbstractKotlinInspection() { } private fun isKeyword(text: String): Boolean { - return text == "yield" || (KtTokens.KEYWORDS.types + KtTokens.SOFT_KEYWORDS.types).any { it.toString() == text } + return text == "yield" || text == "_" || (KtTokens.KEYWORDS.types + KtTokens.SOFT_KEYWORDS.types).any { it.toString() == text } } private fun isRedundantBackticks(node: ASTNode): Boolean { diff --git a/idea/testData/inspectionsLocal/removeRedundantBackticks/underscore.kt b/idea/testData/inspectionsLocal/removeRedundantBackticks/underscore.kt new file mode 100644 index 00000000000..6e8ffeee49d --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantBackticks/underscore.kt @@ -0,0 +1,8 @@ +// PROBLEM: none + +fun test() { + try { + } catch (_: Throwable) { + `_`.printStackTrace() + } +} \ 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 44198be5dba..d63b3bff6d8 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -5474,6 +5474,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/removeRedundantBackticks/property.kt"); } + @TestMetadata("underscore.kt") + public void testUnderscore() throws Exception { + runTest("idea/testData/inspectionsLocal/removeRedundantBackticks/underscore.kt"); + } + @TestMetadata("yield.kt") public void testYield() throws Exception { runTest("idea/testData/inspectionsLocal/removeRedundantBackticks/yield.kt");