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

Useless assignment false positive with additional assignment inside loop #2701

Closed
owst opened this issue Jan 22, 2016 · 1 comment
Closed

Comments

@owst
Copy link
Contributor

owst commented Jan 22, 2016

In the following code, the first assignment to ret is not useless if the loop does not execute:

def while(param)
  ret = 1

  while param != 10
    param += 2
    ret = param + 1
  end

  ret
end

However, rubocop emits the following:

loop_assignment_testcase.rb:2:3: W: Useless assignment to variable - ret.
  ret = 1
  ^^^

this was checked against master:

0.36.0 (using Parser 2.3.0.1, running on ruby 2.2.3 x86_64-darwin14)

I suggest that since the loop is only conditionally executed, the earlier assignment to ret should not be considered useless, as is done for if expressions.

@owst
Copy link
Contributor Author

owst commented Jan 22, 2016

I think #2702 resolves this.

bbatsov added a commit that referenced this issue Jan 24, 2016
…idered_conditional

[Fix #2701] Consider loops as branching points
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant