Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnnecessaryLet false positive when let is used for destructuring #2966

Closed
jcornaz opened this issue Aug 13, 2020 · 1 comment · Fixed by #2968
Closed

UnnecessaryLet false positive when let is used for destructuring #2966

jcornaz opened this issue Aug 13, 2020 · 1 comment · Fixed by #2968

Comments

@jcornaz
Copy link

jcornaz commented Aug 13, 2020

Expected Behavior

I don't expect UnnecessaryLet to be reported for the following code:

val y = x.let { (a, b) -> a + b }

That is because, in this case, let is necessary for destructuring. If I really, want to get rid of let I have to destructure in a val (a, b) = x assigment. And to not let a and b leak in the scope, I'd have to replace val y = x.let { (a, b) -> a + b} by val y = run { val (a, b) = x ; a + b }. Not really an improvement in my opinion.

Observed Behavior

An UnnecessaryLet is reported for the code above.

Steps to Reproduce

  1. Enable UnnecessaryLet rule
  2. Write:
fun foo(x: Pair<Int, Int>): Int = x.let { (a, b) -> a + b }
  1. Run detekt

Your Environment

  • Version of detekt used: 1.11.0-RC2
@arturbosch
Copy link
Member

Cool use case for let I wasn't aware off 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants