-
Notifications
You must be signed in to change notification settings - Fork 197
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
Stop unsafely binding a new variable #1131
Conversation
Currently, hlint will suggest turning `zipWith (+) xs (repeat x)` into `map (\ x -> (+) x x) xs`, which is wrong. The problem is that it's not safe to bind a new variable and use user-provided expressions in the same scope. This change results in it suggesting the correct `map (+ x) xs` instead.
Good catch!
|
It looks to me like hlint will automatically make a lambda if |
Also, I don't understand why the test is still failing after my second commit. Can you take a look at that? |
I had no idea that HLint would automatically make a lambda if the variable was too complicated. Can we add a test for that? Something like:
The test above is failing because of refactoring not working properly, cc @zliu41 - I think this is the only instance we're aware of where refactoring is broken for an LHS/RHS hint. To suppress it for now add
|
Yeah this is a bug in apply-refact. When a substitution variable ( |
Annoyingly, the actual RHS you get from that is |
Don't really mind that it's |
I ended up fixing the test suite by copying over the dubious result with the excess brackets. I've also raised #1132 which properly explains the issue, why, and how we might fix it. Might be a bit of work so can be lower priority. |
Currently, hlint will suggest turning
zipWith (+) xs (repeat x)
intomap (\ x -> (+) x x) xs
, which is wrong. The problem is that it's not safe to bind a new variable and use user-provided expressions in the same scope. This change results in it suggesting the correctmap (+ x) xs
instead.