Weird error spans in patterns
I just copied this code from base in a file to test something:
charIsRepresentable :: TextEncoding -> Char -> IO Bool
charIsRepresentable !enc c =
withCString enc [c]
(\cstr -> do str <- peekCString enc cstr
case str of
[ch] | ch == c -> pure True
_ -> pure False)
`catch`
\(_ :: IOException) -> pure False
and these are the errors I got:
Test.hs:4:21: warning: [-Wmissing-space-after-bang]
Did you forget to enable BangPatterns?
If you mean to bind (!) then perhaps you want
to add a space after the bang for clarity.
|
4 | charIsRepresentable !enc c =
| ^^^^^^
Test.hs:4:22: error: Parse error in pattern: enc
|
4 | charIsRepresentable !enc c =
| ^^^^^
The main problem is that the span is too large: only the !enc
part is the
problem, not c
. Also in the second error the "bang" is outside of the span.
Another problem is I think these should be merged into one error. The first
message already explains the problem: I either need to enable BangPatterns or
add a space after !
. After that the latter is not helpful.