Fix: dont suggest "Use :" when OverloadedLists is enabled (fixes #1602)#1686
Open
mgajda wants to merge 1 commit into
Open
Fix: dont suggest "Use :" when OverloadedLists is enabled (fixes #1602)#1686mgajda wants to merge 1 commit into
mgajda wants to merge 1 commit into
Conversation
…itchell#1602) With OverloadedLists, `\x -> [x]` and `(: [])` have different types: the former produces any IsList instance (Vector a, Set a, NonEmpty a, ...) while the latter specialises to [a]. Applying the suggestion produces code that no longer type-checks. Move the hint from data/hlint.yaml into a code-based hint in Hint/List.hs, gated on `not overloadedListsOn` (same pattern as ndmitchell#114 for "Use list literal" and ndmitchell#1674 for "Use unwords"). The hint still fires for `\x -> [x]` when the module does not enable OverloadedLists, and is suppressed per-file when it does. Tests added to the TEST block in Hint/List.hs. Self-test: 966 tests, all pass.
035a4bb to
3967b6d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1602.
With
OverloadedLists,\x -> [x]and(: [])have different types: the former produces anyIsListinstance (Vector a,Set a,NonEmpty a, …) while the latter specialises to[a]. Applying the suggestion produces code that no longer type-checks.Move the hint from
data/hlint.yamlinto a code-based hint insrc/Hint/List.hs, gated onnot overloadedListsOn(same pattern as #114 for "Use list literal").The hint still fires for
\x -> [x]when the module does not enableOverloadedLists, and is suppressed per-file when it does.Tests added to the TEST block in
src/Hint/List.hs. Self-test: 966 tests, all pass.