Skip to content

Fix: dont suggest "Use :" when OverloadedLists is enabled (fixes #1602)#1686

Open
mgajda wants to merge 1 commit into
ndmitchell:masterfrom
mgajda:fix/use-cons-overloaded-lists
Open

Fix: dont suggest "Use :" when OverloadedLists is enabled (fixes #1602)#1686
mgajda wants to merge 1 commit into
ndmitchell:masterfrom
mgajda:fix/use-cons-overloaded-lists

Conversation

@mgajda
Copy link
Copy Markdown

@mgajda mgajda commented Apr 19, 2026

Fixes #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 src/Hint/List.hs, gated on not overloadedListsOn (same pattern as #114 for "Use list literal").

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 src/Hint/List.hs. Self-test: 966 tests, all pass.

…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.
@mgajda mgajda force-pushed the fix/use-cons-overloaded-lists branch from 035a4bb to 3967b6d Compare April 19, 2026 17:57
@mgajda mgajda changed the title Add OverloadedLists caveat note to "Use :" hint (fixes #1602) Fix: dont suggest "Use :" when OverloadedLists is enabled (fixes #1602) Apr 19, 2026
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

Successfully merging this pull request may close these issues.

use : [] is not correct in the presence of OverloadedLists

1 participant