Fix ReturnCount false positive when excludeReturnFromLambda is enabled - #5459
Conversation
| private val excludeLabeled: Boolean by config(false) | ||
|
|
||
| @Configuration("if labeled return from a lambda should be ignored") | ||
| @Configuration("if labeled return from a lambda should be ignored (takes precedence over excludeLabeled.") |
There was a problem hiding this comment.
| @Configuration("if labeled return from a lambda should be ignored (takes precedence over excludeLabeled.") | |
| @Configuration("if labeled return from a lambda should be ignored (takes precedence over excludeLabeled).") |
There was a problem hiding this comment.
On second thought, the configurations for excluding seem to be or conditions. (The added explanation is only making more confusion for the user). So I revert it.
| .none() | ||
| .not() |
There was a problem hiding this comment.
.none().not() is sort of confusing here. Can we rewrite with any or count() >= 1
There was a problem hiding this comment.
.count() will unnecessarily materialize the sequence. .any() returns a Boolean and will only materialize at most one element of the sequence.
There was a problem hiding this comment.
it's a Sequence, isNotEmpty is only on Collections, because for a "sequence" emptiness doesn't mathematically make sense: "Unlike collections, sequences don't contain elements, they produce them."
Fixes #5341
When excludeReturnFromLambda is enabled, then ignore every labeled return in lambda block.
There can be some extra cases like below, which may go against
excludeReturnFromLambda's general purpose. (do not count return for lambda)But for a clear definition of the
excludeReturnFromLambda(if the labeled return from a lambda should be ignored), I excluded it.