ndmitchell / hlint

Haskell source code suggestions
Other
1.47k stars 196 forks source link

Parse error on nested ViewPatterns #771

Closed dcastro closed 4 years ago

dcastro commented 5 years ago

The parser fails when you use ViewPatterns twice in the same pattern, e.g. (f -> g -> a)

./src/FlatBuffers/Internal/Compiler/NamingConventions.hs:27:29: Error: Parse error
Found:
    getter :: (HasIdent parent, HasIdent field) => parent -> field -> Text
  > getter (getIdent -> unIdent -> parent) (getIdent -> unIdent -> field) =
      TM.toCamel parent <> TM.toPascal field

I suspect this needs to be reported upstream, but I'm not sure whether that means ghc-lib-parser or haskell-src-extras.

josephcsible commented 5 years ago

While this is definitely a legitimate bug, is there a reason that you don't just do (unIdent . getIdent -> parent) instead of (getIdent -> unIdent -> parent)?

ndmitchell commented 5 years ago

It's an HSE bug but odds are it will go away when we complete the move to GHC. It's also a good hint to add!

dcastro commented 5 years ago

Thanks all! I ended up going with unIdent . getIdent

unclechu commented 4 years ago

Please add the note about this to the README.

ndmitchell commented 4 years ago

@unclechu I added a note under https://github.com/ndmitchell/hlint/blob/master/README.md#why-do-i-get-a-parse-error

unclechu commented 4 years ago

@ndmitchell Cool, but I think it would be better to mention explicitly ViewPatterns extension and that a way to solve it is to not using nested patterns, by replacing them where possible with composed functions.

ndmitchell commented 4 years ago

@unclechu I don't think nested view patterns are sufficiently common to warrant a special mention - there are plenty of other constructs that have got more reports about them, e.g. a variable named pattern as per #216. If someone showed me data about what were the most common parse errors and their reasons, I'd certainly include the top 2-3 in the README explicitly, but I suspect (with no real evidence!) it's not nested view patterns.

ndmitchell commented 4 years ago

Confirmed works with HEAD that doesn't use HSE for parsing, so fixed in the next release.