diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractResultUnusedChecker.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractResultUnusedChecker.kt index 272cb4d8441..115e799ea0b 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractResultUnusedChecker.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/inspections/AbstractResultUnusedChecker.kt @@ -15,12 +15,12 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode abstract class AbstractResultUnusedChecker( - private val expressionChecker: (KtExpression) -> Boolean, - private val callChecker: (ResolvedCall<*>) -> Boolean + private val expressionChecker: (KtExpression, AbstractResultUnusedChecker) -> Boolean, + private val callChecker: (ResolvedCall<*>, AbstractResultUnusedChecker) -> Boolean ) : AbstractKotlinInspection() { protected fun check(expression: KtExpression): Boolean { // Check whatever possible by PSI - if (!expressionChecker(expression)) return false + if (!expressionChecker(expression, this)) return false var parent: PsiElement? = expression.parent while (parent != null) { if (parent is KtBlockExpression || parent is KtFunction || parent is KtFile) break @@ -32,6 +32,6 @@ abstract class AbstractResultUnusedChecker( val context = expression.analyze(BodyResolveMode.PARTIAL_WITH_CFA) if (expression.isUsedAsExpression(context)) return false val resolvedCall = expression.getResolvedCall(context) ?: return false - return callChecker(resolvedCall) + return callChecker(resolvedCall, this) } } \ No newline at end of file diff --git a/idea/resources/inspectionDescriptions/AsyncResultUnused.html b/idea/resources/inspectionDescriptions/AsyncResultUnused.html deleted file mode 100644 index c6a81a7035d..00000000000 --- a/idea/resources/inspectionDescriptions/AsyncResultUnused.html +++ /dev/null @@ -1,6 +0,0 @@ - - -This inspection reports async call that is never used, -so all actions inside async are never executed. - - \ No newline at end of file diff --git a/idea/resources/inspectionDescriptions/DeferredResultUnused.html b/idea/resources/inspectionDescriptions/DeferredResultUnused.html new file mode 100644 index 00000000000..cddabfd76db --- /dev/null +++ b/idea/resources/inspectionDescriptions/DeferredResultUnused.html @@ -0,0 +1,6 @@ + + +This inspection reports calls with kotlinx.coroutines.experimental.Deferred result that is never used, +so nobody will wait for execution of all related actions. + + \ No newline at end of file diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index a4112b7ca44..339cb78fb39 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -2854,8 +2854,8 @@ language="kotlin" /> - - - - - - = shortNames.mapTo(mutableSetOf()) { FqName("kotlinx.coroutines.experimental.$it") } + + private val deferred = FqName("kotlinx.coroutines.experimental.Deferred") + } +} \ No newline at end of file diff --git a/idea/testData/inspections/coroutines/asyncResultUnused/inspectionData/expected.xml b/idea/testData/inspections/coroutines/asyncResultUnused/inspectionData/expected.xml index e77788b5f3b..0e259e03f44 100644 --- a/idea/testData/inspections/coroutines/asyncResultUnused/inspectionData/expected.xml +++ b/idea/testData/inspections/coroutines/asyncResultUnused/inspectionData/expected.xml @@ -5,7 +5,25 @@ light_idea_test_case <default> - Result of 'async' is not used - Result of 'async' is never used + Deferred result is never used + Deferred result is never used + + + simple.kt + 49 + light_idea_test_case + <default> + + Deferred result is never used + Deferred result is never used + + + simple.kt + 51 + light_idea_test_case + <default> + + Deferred result is never used + Deferred result is never used \ No newline at end of file diff --git a/idea/testData/inspections/coroutines/asyncResultUnused/inspectionData/inspections.test b/idea/testData/inspections/coroutines/asyncResultUnused/inspectionData/inspections.test index 4b6b3d052a1..44a5dcb810a 100644 --- a/idea/testData/inspections/coroutines/asyncResultUnused/inspectionData/inspections.test +++ b/idea/testData/inspections/coroutines/asyncResultUnused/inspectionData/inspections.test @@ -1 +1 @@ -// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.coroutines.AsyncResultUnusedInspection +// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.coroutines.DeferredResultUnusedInspection diff --git a/idea/testData/inspections/coroutines/asyncResultUnused/inspectionData/settings.xml b/idea/testData/inspections/coroutines/asyncResultUnused/inspectionData/settings.xml new file mode 100644 index 00000000000..030a2b8ae0a --- /dev/null +++ b/idea/testData/inspections/coroutines/asyncResultUnused/inspectionData/settings.xml @@ -0,0 +1,3 @@ + + diff --git a/idea/testData/inspections/coroutines/asyncResultUnused/simple.kt b/idea/testData/inspections/coroutines/asyncResultUnused/simple.kt index 07c01df416f..1a86eedf15e 100644 --- a/idea/testData/inspections/coroutines/asyncResultUnused/simple.kt +++ b/idea/testData/inspections/coroutines/asyncResultUnused/simple.kt @@ -37,3 +37,18 @@ fun falsePositives() { val res = async { 13 } useIt(async { 7 }) } + +class User + +interface DbHandler { + fun getUser(id: Long): Deferred + fun doStuff(): Deferred +} + +fun DbHandler.test() { + getUser(42L) + val user = getUser(42L).await() + doStuff() + doStuff().await() +} +