"Redundant suspend modifier": fix false negative with only recursive call
#KT-35829 Fixed
This commit is contained in:
committed by
Ilya Kirillov
parent
e3871a9961
commit
1f6b7dd88d
+13
-3
@@ -17,8 +17,11 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
|
||||
import org.jetbrains.kotlin.idea.highlighter.hasSuspendCalls
|
||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||
import org.jetbrains.kotlin.idea.quickfix.RemoveModifierFix
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.psi.namedFunctionVisitor
|
||||
import org.jetbrains.kotlin.psi.psiUtil.anyDescendantOfType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -36,9 +39,7 @@ class RedundantSuspendModifierInspection : AbstractKotlinInspection() {
|
||||
val descriptor = context[BindingContext.FUNCTION, function] ?: return
|
||||
if (descriptor.modality == Modality.OPEN) return
|
||||
|
||||
if (function.anyDescendantOfType<KtExpression> { it.hasSuspendCalls(context) }) {
|
||||
return
|
||||
}
|
||||
if (function.hasSuspendCalls(context)) return
|
||||
|
||||
holder.registerProblem(
|
||||
suspendModifier,
|
||||
@@ -51,4 +52,13 @@ class RedundantSuspendModifierInspection : AbstractKotlinInspection() {
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
private fun KtNamedFunction.hasSuspendCalls(context: BindingContext): Boolean {
|
||||
return anyDescendantOfType<KtExpression> {
|
||||
if (it is KtNameReferenceExpression && it.getReferencedName() == this.name && it.mainReference.resolve() == this) {
|
||||
return@anyDescendantOfType false
|
||||
}
|
||||
it.hasSuspendCalls(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<caret>suspend fun foo() {
|
||||
foo()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo() {
|
||||
foo()
|
||||
}
|
||||
+5
@@ -8335,6 +8335,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
public void testParenthesized() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/redundantSuspend/parenthesized.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("recursiveCall.kt")
|
||||
public void testRecursiveCall() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/redundantSuspend/recursiveCall.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/inspectionsLocal/redundantUnitExpression")
|
||||
|
||||
Reference in New Issue
Block a user