Strange behavior when pattern variables are duplicated on pattern synonym RHS
These might be two separate bugs, but they're similar enough that I'll bundle them under the same ticket.
If you take a pattern variable bound on the LHS of a unidirectional pattern synonym and use it multiple locations on the RHS, then GHC accepts it, surprisingly:
pattern Foo a <- (a,a)
Foo do? As it turns out, the right-most occurrence of
a in the RHS seems to take precedence:
λ> :i Foo pattern Foo :: b -> (a, b) -- Defined at <interactive>:12:1 λ> case ('a', 'b') of Foo x -> x 'b'
I expect the definition of
Foo to error.
When duplicate pattern variables are used in the RHS of an implicitly bidirectional pattern synonym, then it does error. However, the error message is quite misleading:
λ> pattern Foo a = (a,a) <interactive>:16:17: error: Invalid right-hand side of bidirectional pattern synonym ‘Foo’: ‘a’ is not bound by the LHS of the pattern synonym RHS pattern: (a, a)