NI: add fallback strategy to get lexical scope to checking coroutine call legality

^KT-40247 Fixed
^KT-40337 Fixed
This commit is contained in:
Victor Petukhov
2020-07-16 11:08:12 +03:00
parent 5951e7500a
commit e754585e38
8 changed files with 83 additions and 2 deletions
@@ -64,10 +64,10 @@ fun findEnclosingSuspendFunction(context: CallCheckerContext, checkingCall: KtEl
val scope = if (context.resolutionContext !is CallResolutionContext<*> || context.resolutionContext.call.callElement == checkingCall) {
context.scope
} else {
context.trace.get(BindingContext.LEXICAL_SCOPE, checkingCall)
context.trace.get(BindingContext.LEXICAL_SCOPE, checkingCall) ?: context.scope
}
return scope?.parentsWithSelf?.firstOrNull {
return scope.parentsWithSelf.firstOrNull {
it is LexicalScope && it.kind in ALLOWED_SCOPE_KINDS && it.ownerDescriptor.safeAs<FunctionDescriptor>()?.isSuspend == true
}?.cast<LexicalScope>()?.ownerDescriptor?.cast()
}