From 4cf83d952625b4cef9025b3f5ba225aebd6958c3 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Wed, 15 Apr 2020 10:54:59 +0900 Subject: [PATCH] Redundant semicolon: don't report when semicolon is between type and '!' #KT-38240 Fixed --- .../idea/inspections/RedundantSemicolonInspection.kt | 10 +++++++--- .../redundantSemicolon/betweenTypeAndNotOperator.kt | 9 +++++++++ .../idea/inspections/LocalInspectionTestGenerated.java | 5 +++++ 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 idea/testData/inspectionsLocal/redundantSemicolon/betweenTypeAndNotOperator.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt index 89bb0f33a0b..28ac4748972 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt @@ -90,9 +90,13 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns return false } - val prevNameReference = semicolon.getPrevSiblingIgnoringWhitespaceAndComments() as? KtNameReferenceExpression - if (prevNameReference != null && prevNameReference.text in softModifierKeywords - && semicolon.getNextSiblingIgnoringWhitespaceAndComments() is KtDeclaration + val prevSibling = semicolon.getPrevSiblingIgnoringWhitespaceAndComments() + val nextSibling = semicolon.getNextSiblingIgnoringWhitespaceAndComments() + if (prevSibling.safeAs()?.text in softModifierKeywords && + nextSibling is KtDeclaration + ) return false + if (nextSibling.safeAs()?.operationToken == KtTokens.EXCL && + semicolon.prevLeaf()?.getStrictParentOfType() != null ) return false return true diff --git a/idea/testData/inspectionsLocal/redundantSemicolon/betweenTypeAndNotOperator.kt b/idea/testData/inspectionsLocal/redundantSemicolon/betweenTypeAndNotOperator.kt new file mode 100644 index 00000000000..48083aac70f --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSemicolon/betweenTypeAndNotOperator.kt @@ -0,0 +1,9 @@ +// PROBLEM: none +fun test(a: Any) { + foo { + val b = a as Boolean; + !b + } +} + +fun foo(f: () -> Boolean) {} \ 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 10e5ab2dc8a..05d31238d02 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -8416,6 +8416,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/redundantSemicolon/betweenSoftModifierKeywordAndDeclaration3.kt"); } + @TestMetadata("betweenTypeAndNotOperator.kt") + public void testBetweenTypeAndNotOperator() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantSemicolon/betweenTypeAndNotOperator.kt"); + } + @TestMetadata("companionBeforeFun.kt") public void testCompanionBeforeFun() throws Exception { runTest("idea/testData/inspectionsLocal/redundantSemicolon/companionBeforeFun.kt");