[commit: ghc] master: Comments only (isIrrefutablePat) (52b02e6)
git at git.haskell.org
git at git.haskell.org
Wed Dec 2 14:42:32 UTC 2015
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/52b02e66025f029ca1b99dfccedca909fdc86831/ghc
>---------------------------------------------------------------
commit 52b02e66025f029ca1b99dfccedca909fdc86831
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Wed Dec 2 14:38:42 2015 +0000
Comments only (isIrrefutablePat)
>---------------------------------------------------------------
52b02e66025f029ca1b99dfccedca909fdc86831
compiler/hsSyn/HsPat.hs | 8 ++++++--
compiler/rename/RnExpr.hs | 5 +++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/compiler/hsSyn/HsPat.hs b/compiler/hsSyn/HsPat.hs
index 24ef065..359990a 100644
--- a/compiler/hsSyn/HsPat.hs
+++ b/compiler/hsSyn/HsPat.hs
@@ -540,8 +540,12 @@ isIrrefutableHsPat :: OutputableBndr id => LPat id -> Bool
-- (NB: this is not quite the same as the (silly) defn
-- in 3.17.2 of the Haskell 98 report.)
--
--- isIrrefutableHsPat returns False if it's in doubt; specifically
--- on a ConPatIn it doesn't know the size of the constructor family
+-- WARNING: isIrrefutableHsPat returns False if it's in doubt.
+-- Specifically on a ConPatIn, which is what it sees for a
+-- (LPat Name) in the renamer, it doesn't know the size of the
+-- constructor family, so it returns False. Result: only
+-- tuple patterns are considered irrefuable at the renamer stage.
+--
-- But if it returns True, the pattern is definitely irrefutable
isIrrefutableHsPat pat
= go pat
diff --git a/compiler/rename/RnExpr.hs b/compiler/rename/RnExpr.hs
index 035b4db..5df96cf 100644
--- a/compiler/rename/RnExpr.hs
+++ b/compiler/rename/RnExpr.hs
@@ -1437,6 +1437,11 @@ ado _ctxt [] tail _ = return (tail, emptyNameSet)
-- the bind form, which would give rise to a Monad constraint.
ado ctxt [(L _ (BindStmt pat rhs _ _),_)] tail _
| isIrrefutableHsPat pat, (False,tail') <- needJoin tail
+ -- WARNING: isIrrefutableHsPat on (HsPat Name) doesn't have enough info
+ -- to know which types have only one constructor. So only
+ -- tuples come out as irrefutable; other single-constructor
+ -- types, and newtypes, will not. See the code for
+ -- isIrrefuatableHsPat
= mkApplicativeStmt ctxt [ApplicativeArgOne pat rhs] False tail'
ado _ctxt [(one,_)] tail _ = return (one:tail, emptyNameSet)
More information about the ghc-commits
mailing list