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

False positive Lint/UselessAssign #468

Closed
Blacksmoke16 opened this issue Aug 20, 2024 · 2 comments · Fixed by #485
Closed

False positive Lint/UselessAssign #468

Blacksmoke16 opened this issue Aug 20, 2024 · 2 comments · Fixed by #485
Assignees
Milestone

Comments

@Blacksmoke16
Copy link
Contributor

Blacksmoke16 commented Aug 20, 2024

hash = {"foo" => "bar"}

def call(v)
end

unless v = hash["foo"]?
  call v = "default"
end

v

Results in:

[W] Lint/UselessAssign: Useless assignment to variable `v`
> unless v = hash["foo"]?

The assignment is for sure not useless as it handles assigning v if that key is present in the hash, otherwise is assigned within the unless block.

Creating a new issue as unlike #447, this doesn't require any type declarations or macros.

@Sija
Copy link
Member

Sija commented Oct 13, 2024

Reduced:

unless v = rand
  puts v = 1
end
v
puts v = 1 unless v = rand
v

@Sija
Copy link
Member

Sija commented Oct 13, 2024

I'd say the bug is most likely located somewhere in the AST::ScopeVisitor class, yet I couldn't exactly pinpoint it.

@veelenga any pointers?

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.

3 participants