Poor SrcSpan for recursive pattern synonym error message
If you compile this code:
{-# LANGUAGE PatternSynonyms #-}
module Bug where
pattern P1 = P2
pattern P2 = P1
You'll get this error message:
$ /opt/ghc/8.6.5/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:1:1: error:
Recursive pattern synonym definition with following bindings:
P1 (defined at Bug.hs:4:1-15)
P2 (defined at Bug.hs:5:1-15)
|
1 | {-# LANGUAGE PatternSynonyms #-}
| ^
While the guts of the error message do correctly identify the pattern synonyms involved in the recursive group, the caret points to line one, column one, which has absolutely nothing to do with P1
or P2
. A more sensible thing to do would be to emulate the location of this program's error message:
module Bug where
type P1 = P2
type P2 = P1
$ /opt/ghc/8.6.5/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:3:1: error:
Cycle in type synonym declarations:
Bug.hs:3:1-12: type P1 = P2
Bug.hs:4:1-12: type P2 = P1
|
3 | type P1 = P2
| ^^^^^^^^^^^^
This time, the caret points to the first type synonym declaration involved in the recursive group, which is as reasonable a choice as anything. It would make sense to do the same thing for recursive pattern synonym groups as well.
Patch incoming.