Redundant semicolon: don't report when semicolon is between type and '!'

#KT-38240 Fixed
This commit is contained in:
Toshiaki Kameyama
2020-04-15 10:54:59 +09:00
committed by Yan Zhulanow
parent 8e8171547b
commit 4cf83d9526
3 changed files with 21 additions and 3 deletions
@@ -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<KtNameReferenceExpression>()?.text in softModifierKeywords &&
nextSibling is KtDeclaration
) return false
if (nextSibling.safeAs<KtPrefixExpression>()?.operationToken == KtTokens.EXCL &&
semicolon.prevLeaf()?.getStrictParentOfType<KtTypeReference>() != null
) return false
return true
@@ -0,0 +1,9 @@
// PROBLEM: none
fun test(a: Any) {
foo {
val b = a as Boolean;<caret>
!b
}
}
fun foo(f: () -> Boolean) {}
@@ -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");