Disallow bang/lazy patterns in the RHSes of implicitly bidirectional patsyns
authorRyan Scott <ryan.gl.scott@gmail.com>
Sat, 2 Sep 2017 19:33:11 +0000 (15:33 -0400)
committerRyan Scott <ryan.gl.scott@gmail.com>
Sat, 2 Sep 2017 19:33:12 +0000 (15:33 -0400)
commit5dd6b13c6e2942976aa3b5f4906ff7d0f959272d
tree233df1050c497f1accc7a3ded00fa4bd9f71ee6e
parent6330b0b0938bc7b27463b3bbfa0df661e4a966b1
Disallow bang/lazy patterns in the RHSes of implicitly bidirectional patsyns

Summary:
GHC was allowing implicitly bidirectional pattern synonyms with bang
patterns and irrefutable patterns in the RHS, like so:

```lang=haskell
pattern StrictJust a = Just !a
```

This has multiple problems:

1. `Just !a` isn't a valid expression, so it feels strange to allow it in an
   implicitly bidirectional pattern synonym.
2. `StrictJust` doesn't provide the strictness properties one would expect
   from a strict constructor. (One could imagine a design where the
   `StrictJust` builder infers a bang pattern for its pattern variable, but
   accomplishing this inference in a way that accounts for all possible
   patterns on the RHS, including other pattern synonyms, is somewhat
   awkward, so we do not pursue this design.)

We nip these issues in the bud by simply disallowing bang/irrefutable patterns
on the RHS.

Test Plan: make test TEST="T14112 unidir"

Reviewers: simonpj, austin, bgamari

Reviewed By: simonpj

Subscribers: rwbarton, thomie

GHC Trac Issues: #14112

Differential Revision: https://phabricator.haskell.org/D3896
compiler/typecheck/TcPatSyn.hs
docs/users_guide/8.4.1-notes.rst
docs/users_guide/glasgow_exts.rst
testsuite/tests/patsyn/should_fail/T14112.hs [new file with mode: 0644]
testsuite/tests/patsyn/should_fail/T14112.stderr [new file with mode: 0644]
testsuite/tests/patsyn/should_fail/all.T
testsuite/tests/patsyn/should_fail/unidir.stderr