183: Fix exception about unmapped lambda argument from IDE inspection

Intention: obtain lambda argument for some parent call,
 then get that call (for the lambda argument) and map
 the argument to the parameter.

 Before the fix, we were getting call for inner element,
 not for the lambda argument and as a result, there were exceptions.

 #KT-26873 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2018-09-26 14:41:37 +03:00
parent c1b3e72ae8
commit d0ed76ebc8
3 changed files with 17 additions and 1 deletions
@@ -44,7 +44,7 @@ class CoroutineNonBlockingContextChecker : NonBlockingContextChecker {
.firstOrNull { it is KtLambdaExpression && it.analyze().get(BindingContext.LAMBDA_INVOCATIONS, it) == null }
val containingArgument = PsiTreeUtil.getParentOfType(containingLambda, KtValueArgument::class.java)
if (containingArgument != null) {
val callExpression = PsiTreeUtil.getParentOfType(element, KtCallExpression::class.java) ?: return false
val callExpression = PsiTreeUtil.getParentOfType(containingArgument, KtCallExpression::class.java) ?: return false
val call = callExpression.resolveToCall(BodyResolveMode.FULL) ?: return false
val hasBlockingAnnotation = call.getFirstArgument()?.resolveToCall()
@@ -0,0 +1,11 @@
fun <T> runBlocking(<warning descr="[UNUSED_PARAMETER] Parameter 'block' is never used">block</warning>: suspend CoroutineScope.() -> T): T = TODO()
class CoroutineScope
fun test() {
runBlocking {
repeat(1) {
java.lang.Thread.<warning descr="Inappropriate blocking method call">sleep</warning>(2)
}
}
}
@@ -38,4 +38,9 @@ class CoroutineNonBlockingontextDetectionTest: KotlinLightCodeInsightFixtureTest
myFixture.configureByFile("LambdaReceiverTypeCheck.kt")
myFixture.testHighlighting(true, false, false, "LambdaReceiverTypeCheck.kt")
}
fun testNestedFunctionsInsideSuspendLambda() {
myFixture.configureByFile("NestedFunctionsInsideSuspendLambda.kt")
myFixture.testHighlighting(true, false, false, "NestedFunctionsInsideSuspendLambda.kt")
}
}