-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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' reported when setting atttribute on method parameter #438
Comments
Parameters are treated as local vars by the parser and assignments to local vars as the result of a functions generally make no sense. Assignment to parameters is considered extremely bad style anyways... |
I completely agree on style. Nevertheless the code actually does something and has an effect outside of that method call. |
The problem is that we cannot simply allow assignments to params, because of code like this: def add_to_hash(test_class, value)
test_class = NewClass.new
# there is a param test_class, but this is no longer it
test_class.member = value
end Checking for assignments to all the params might be one solution (not sure how robust, though) - if there are no, we assume this is still a param and it's OK to assign to it. @yujinakayama Would you volunteer to fix this issue? :-) |
OK 👍 |
Then there are a number of special cases that make the assignment "not useless". I don't know if they're too far-fetched or if we should worry about them.
|
The following code results in a warning:
Useless assignment to local variable test_class.
fortest_class.member = value
:The text was updated successfully, but these errors were encountered: