Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sanggggg
Copy link
Contributor

@sanggggg sanggggg commented Oct 21, 2022

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)

fun asdf() {
  kotlin.run {
    return@asdf // do not counted when if excludeReturnFromLambda is enabled.
  }
}

But for a clear definition of the excludeReturnFromLambda (if the labeled return from a lambda should be ignored), I excluded it.

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.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@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).")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

1b806d8

Comment on lines 116 to 117
.none()
.not()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.none().not() is sort of confusing here. Can we rewrite with any or count() >= 1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.count() will unnecessarily materialize the sequence. .any() returns a Boolean and will only materialize at most one element of the sequence.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be isNotEmpty?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BraisGabin BraisGabin added this to the 1.22.0 milestone Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReturnCount false positive on lambda returns

4 participants