[commit: ghc] ghc-8.2: HsPat: Assume that no spliced patterns are irrefutable (b45d127)
git at git.haskell.org
git at git.haskell.org
Fri Jul 21 02:16:15 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-8.2
Link : http://ghc.haskell.org/trac/ghc/changeset/b45d1277ada4b5ce30d5cfa188fb020f4806d9ea/ghc
>---------------------------------------------------------------
commit b45d1277ada4b5ce30d5cfa188fb020f4806d9ea
Author: Ben Gamari <bgamari.foss at gmail.com>
Date: Thu Jul 20 19:24:00 2017 -0400
HsPat: Assume that no spliced patterns are irrefutable
This is a conservative assumption which will limit some uses of spliced
patterns, but it fixes #13984.
Test Plan: Validate
Reviewers: RyanGlScott, AaronFriel, austin
Reviewed By: RyanGlScott
Subscribers: rwbarton, thomie
GHC Trac Issues: #13984
Differential Revision: https://phabricator.haskell.org/D3766
(cherry picked from commit 36e8bcba08446dbc4e7532ef9db5517c13977bf9)
>---------------------------------------------------------------
b45d1277ada4b5ce30d5cfa188fb020f4806d9ea
compiler/hsSyn/HsPat.hs | 16 +++++++---------
testsuite/tests/typecheck/should_compile/T13984.hs | 9 +++++++++
testsuite/tests/typecheck/should_compile/all.T | 1 +
3 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/compiler/hsSyn/HsPat.hs b/compiler/hsSyn/HsPat.hs
index 174e837..23dbd75 100644
--- a/compiler/hsSyn/HsPat.hs
+++ b/compiler/hsSyn/HsPat.hs
@@ -617,7 +617,7 @@ isIrrefutableHsPat pat
go1 (SigPatOut pat _) = go pat
go1 (TuplePat pats _ _) = all go pats
go1 (SumPat pat _ _ _) = go pat
- go1 (ListPat {}) = False
+ go1 (ListPat {}) = False
go1 (PArrPat {}) = False -- ?
go1 (ConPatIn {}) = False -- Conservative
@@ -629,15 +629,13 @@ isIrrefutableHsPat pat
go1 (ConPatOut{ pat_con = L _ (PatSynCon _pat) })
= False -- Conservative
- go1 (LitPat {}) = False
- go1 (NPat {}) = False
- go1 (NPlusKPat {}) = False
+ go1 (LitPat {}) = False
+ go1 (NPat {}) = False
+ go1 (NPlusKPat {}) = False
- -- Both should be gotten rid of by renamer before
- -- isIrrefutablePat is called
- go1 (SplicePat {}) = urk pat
-
- urk pat = pprPanic "isIrrefutableHsPat:" (ppr pat)
+ -- We conservatively assume that no TH splices are irrefutable
+ -- since we cannot know until the splice is evaluated.
+ go1 (SplicePat {}) = False
hsPatNeedsParens :: Pat a -> Bool
hsPatNeedsParens (NPlusKPat {}) = True
diff --git a/testsuite/tests/typecheck/should_compile/T13984.hs b/testsuite/tests/typecheck/should_compile/T13984.hs
new file mode 100644
index 0000000..a17e48c
--- /dev/null
+++ b/testsuite/tests/typecheck/should_compile/T13984.hs
@@ -0,0 +1,9 @@
+{-# LANGUAGE TemplateHaskell #-}
+module Panic where
+
+import Language.Haskell.TH
+
+expr :: IO Exp
+expr = runQ $ do
+ name <- newName "foo"
+ [| do $(varP name) <- pure (); pure () |]
diff --git a/testsuite/tests/typecheck/should_compile/all.T b/testsuite/tests/typecheck/should_compile/all.T
index c33f66f..badb814 100644
--- a/testsuite/tests/typecheck/should_compile/all.T
+++ b/testsuite/tests/typecheck/should_compile/all.T
@@ -560,3 +560,4 @@ test('T13879', normal, compile, [''])
test('T13881', normal, compile, [''])
test('T13915a', normal, multimod_compile, ['T13915a', '-v0'])
test('T13915b', normal, compile, [''])
+test('T13984', normal, compile, [''])
More information about the ghc-commits
mailing list