Skip to content

Commit

Permalink
Fix false-positive on NestedScopeFunctions (#5274)
Browse files Browse the repository at this point in the history
* Don't hide the fact that there are not available descriptors

* Make function return the correct value

* Fix boolean logic
  • Loading branch information
BraisGabin committed Sep 4, 2022
1 parent 6b6d904 commit 37584c2
Showing 1 changed file with 4 additions and 5 deletions.
Expand Up @@ -120,16 +120,15 @@ class NestedScopeFunctions(config: Config = Config.empty) : Rule(config) {
}

private fun KtCallExpression.isScopeFunction(): Boolean {
val descriptors = resolveDescriptors()
return !descriptors.any { it.matchesScopeFunction() }
val descriptors = resolveDescriptors() ?: return false
return descriptors.any { it.matchesScopeFunction() }
}

private fun KtCallExpression.resolveDescriptors(): List<CallableDescriptor> =
private fun KtCallExpression.resolveDescriptors(): List<CallableDescriptor>? =
getResolvedCall(bindingContext)?.resultingDescriptor
?.let { listOf(it) + it.overriddenDescriptors }
.orEmpty()

private fun CallableDescriptor.matchesScopeFunction(): Boolean =
!functions.any { it.match(this) }
functions.any { it.match(this) }
}
}

0 comments on commit 37584c2

Please sign in to comment.