[GHC] #14114: Strange behavior when pattern variables are duplicated on pattern synonym RHS

#14114: Strange behavior when pattern variables are duplicated on pattern synonym RHS -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Keywords: | Operating System: Unknown/Multiple PatternSynonyms | Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- 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: {{{#!hs pattern Foo a <- (a,a) }}} What does `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) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14114 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14114: Strange behavior when pattern variables are duplicated on pattern synonym RHS -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3866 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D3866 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14114#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14114: Strange behavior when pattern variables are duplicated on pattern synonym
RHS
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: (none)
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 8.2.1
Resolution: | Keywords:
| PatternSynonyms
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D3866
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ryan Scott

#14114: Strange behavior when pattern variables are duplicated on pattern synonym RHS -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.2.1 Resolution: fixed | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | patsyn/should_fail/T14114 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3866 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * testcase: => patsyn/should_fail/T14114 * status: patch => closed * resolution: => fixed * milestone: => 8.4.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14114#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC