Has suspend calls: fix suspend iterator case
This commit is contained in:
+14
-6
@@ -85,10 +85,18 @@ private fun KtExpression.isValidCandidateExpression(): Boolean {
|
||||
fun KtExpression.hasSuspendCalls(bindingContext: BindingContext = analyze(BodyResolveMode.PARTIAL)): Boolean {
|
||||
if (!isValidCandidateExpression()) return false
|
||||
|
||||
val resolvedCall = if (this is KtForExpression) {
|
||||
bindingContext[BindingContext.LOOP_RANGE_NEXT_RESOLVED_CALL, loopRange]
|
||||
} else {
|
||||
this.getResolvedCall(bindingContext)
|
||||
} ?: return false
|
||||
return (resolvedCall.resultingDescriptor as? FunctionDescriptor)?.isSuspend == true
|
||||
return when (this) {
|
||||
is KtForExpression -> {
|
||||
val iteratorResolvedCall = bindingContext[BindingContext.LOOP_RANGE_ITERATOR_RESOLVED_CALL, loopRange]
|
||||
val loopRangeHasNextResolvedCall = bindingContext[BindingContext.LOOP_RANGE_HAS_NEXT_RESOLVED_CALL, loopRange]
|
||||
val loopRangeNextResolvedCall = bindingContext[BindingContext.LOOP_RANGE_NEXT_RESOLVED_CALL, loopRange]
|
||||
listOf(iteratorResolvedCall, loopRangeHasNextResolvedCall, loopRangeNextResolvedCall).any {
|
||||
it?.resultingDescriptor?.isSuspend == true
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
val resolvedCall = getResolvedCall(bindingContext)
|
||||
(resolvedCall?.resultingDescriptor as? FunctionDescriptor)?.isSuspend == true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-9
@@ -31,15 +31,6 @@
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant 'suspend' modifier</problem_class>
|
||||
<description>Redundant 'suspend' modifier</description>
|
||||
</problem>
|
||||
<!-- FIXME: Incorrect problem -->
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>57</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant 'suspend' modifier</problem_class>
|
||||
<description>Redundant 'suspend' modifier</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>operators.kt</file>
|
||||
<line>5</line>
|
||||
|
||||
Reference in New Issue
Block a user