Result unused: a few enhancements for PSI checks
Related to KT-15063, KT-24433
This commit is contained in:
+5
-2
@@ -21,11 +21,14 @@ abstract class AbstractResultUnusedChecker(
|
||||
protected fun check(expression: KtExpression): Boolean {
|
||||
// Check whatever possible by PSI
|
||||
if (!expressionChecker(expression, this)) return false
|
||||
var current: PsiElement? = expression
|
||||
var parent: PsiElement? = expression.parent
|
||||
while (parent != null) {
|
||||
if (parent is KtBlockExpression || parent is KtFunction || parent is KtFile) break
|
||||
if (parent is KtValueArgument) return false
|
||||
if (parent is KtBinaryExpression && parent.operationToken in KtTokens.ALL_ASSIGNMENTS) return false
|
||||
if (parent is KtValueArgument || parent is KtBinaryExpression || parent is KtUnaryExpression) return false
|
||||
if (parent is KtQualifiedExpression && parent.receiverExpression == current) return false
|
||||
// TODO: add when condition, if condition (later when it's applicable not only to Deferred)
|
||||
current = parent
|
||||
parent = parent.parent
|
||||
}
|
||||
// Then check by call
|
||||
|
||||
@@ -52,3 +52,10 @@ fun DbHandler.test() {
|
||||
doStuff().await()
|
||||
}
|
||||
|
||||
operator fun Deferred<Int>.unaryPlus() = this
|
||||
operator fun Deferred<Int>.plus(arg: Int) = this
|
||||
|
||||
fun moreFalsePositives() {
|
||||
+(async { 0 })
|
||||
async { -1 } + 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user