ndmitchell / hlint

Haskell source code suggestions
Other
1.45k stars 194 forks source link

Use list literal suggestions with `:|` #1590

Open philderbeast opened 2 months ago

philderbeast commented 2 months ago

With https://github.com/agda/agda/commit/0ff0741244252b46a183b7d5d4f526b7fe8c25f7, and the following diff, I'm getting suggestions that don't compile.

git diff
diff --git a/.hlint.yaml b/.hlint.yaml
index ccd486368..8daec1b5e 100644
--- a/.hlint.yaml
+++ b/.hlint.yaml
@@ -74,7 +74,6 @@
 - ignore: {name: "Use isNothing"} # 2 hints
 - ignore: {name: "Use join"} # 2 hints
 - ignore: {name: "Use lambda-case"} # 11 hints
-- ignore: {name: "Use list literal"} # 12 hints
 - ignore: {name: "Use list literal pattern"} # 1 hint
 - ignore: {name: "Use map once"} # 1 hint
 - ignore: {name: "Use map with tuple-section"} # 4 hints

The suggestions look wrong to me. Here's one I ran through GHCI.

 test/Internal/Utils/Cluster.hs:86:5-37: Suggestion: Use list literal
Found:
  "anabel" :| "bond" : "babel" : []
Perhaps:
  ["anabel" :| "bond", "babel"]

This is not the same.

 $ ghci
GHCi, version 9.8.2: https://www.haskell.org/ghc/  :? for help
ghci> import Data.List.NonEmpty
ghci> "anabel" :| "bond" : "babel" : []
"anabel" :| ["bond","babel"]
ghci> ["anabel" :| "bond", "babel"]

<interactive>:3:3: error: [GHC-39999]
    • No instance for ‘Data.String.IsString Char’
        arising from the literal ‘"anabel"’
    • In the first argument of ‘(:|)’, namely ‘"anabel"’
      In the expression: "anabel" :| "bond"
      In the expression: ["anabel" :| "bond", "babel"]

<interactive>:3:23: error: [GHC-39999]
    • No instance for ‘Data.String.IsString (NonEmpty Char)’
        arising from the literal ‘"babel"’
    • In the expression: "babel"
      In the expression: ["anabel" :| "bond", "babel"]
      In an equation for ‘it’: it = ["anabel" :| "bond", "babel"]

In this instance, shouldn't the suggestion be changed to:


 test/Internal/Utils/Cluster.hs:86:5-37: Suggestion: Use list literal
Found:
   "anabel" :| "bond" : "babel" : []
Perhaps:
- ["anabel" :| "bond", "babel"]
+ "anabel" :| ["bond","babel"]