pointfree
pointfree copied to clipboard
bad error message when parsing fails due to fixity resulution
Consider the following interaction with pointfree, which spouts an error about Template Haskell seemingly out of the blue.
# pointfree 'a . b ? c'
TemplateHaskell language extension is not enabled. Please add {-# LANGUAGE TemplateHaskell #-} pragma at the top of your module.
It turns out that this results from pointfree parsing the input as a declaration if parsing it as an expression fails, because any expression can be parsed as a bare top-level template splice.
Prelude Language.Haskell.Exts> parseExp "a . b ? c"
ParseFailed (SrcLoc "" -1 -1) "Ambiguous infix expression"
Prelude Language.Haskell.Exts> parseDecl "a . b ? c"
ParseFailed (SrcLoc "<unknown>.hs" 1 10) "TemplateHaskell language extension is not enabled. Please add {-# LANGUAGE TemplateHaskell #-} pragma at the top of your module."
Maybe pointfree should print both errors when parsing fails, for example:
# pointfree 'a . b ? c'
parsing as an expression failed with "Ambiguous infix expression"
parsing as a declaration failed with "TemplateHaskell language extension is not enabled. Please add {-# LANGUAGE TemplateHaskell #-} pragma at the top of your module."