summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2017-05-08 14:04:34 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2017-05-09 10:43:54 +0100
commit549c8b33da25371ab1aa1818ef27fc418252e667 (patch)
tree5530e7c2152e113965c641f9a32dd9c21e2dc44b /compiler
parentd46a5102e0911e96a85434e46bbfe8b9ccc86471 (diff)
downloadhaskell-549c8b33da25371ab1aa1818ef27fc418252e667.tar.gz
Don't warn about variable-free strict pattern bindings
See Trac #13646 and the new Note [Pattern bindings that bind no variables]
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rename/RnBinds.hs48
1 files changed, 33 insertions, 15 deletions
diff --git a/compiler/rename/RnBinds.hs b/compiler/rename/RnBinds.hs
index d78ed93d2e..0b4cbeb276 100644
--- a/compiler/rename/RnBinds.hs
+++ b/compiler/rename/RnBinds.hs
@@ -456,21 +456,22 @@ rnBind _ bind@(PatBind { pat_lhs = pat
-- As well as dependency analysis, we need these for the
-- MonoLocalBinds test in TcBinds.decideGeneralisationPlan
bndrs = collectPatBinders pat
- bind' = bind { pat_rhs = grhss',
- pat_rhs_ty = placeHolderType, bind_fvs = fvs' }
- is_wild_pat = case pat of
- L _ (WildPat {}) -> True
- L _ (BangPat (L _ (WildPat {}))) -> True -- #9127
- _ -> False
-
- -- Warn if the pattern binds no variables, except for the
- -- entirely-explicit idiom _ = rhs
- -- which (a) is not that different from _v = rhs
- -- (b) is sometimes used to give a type sig for,
- -- or an occurrence of, a variable on the RHS
+ bind' = bind { pat_rhs = grhss'
+ , pat_rhs_ty = placeHolderType, bind_fvs = fvs' }
+
+ ok_nobind_pat
+ = -- See Note [Pattern bindings that bind no variables]
+ case pat of
+ L _ (WildPat {}) -> True
+ L _ (BangPat {}) -> True -- #9127, #13646
+ _ -> False
+
+ -- Warn if the pattern binds no variables
+ -- See Note [Pattern bindings that bind no variables]
; whenWOptM Opt_WarnUnusedPatternBinds $
- when (null bndrs && not is_wild_pat) $
- addWarn (Reason Opt_WarnUnusedPatternBinds) $ unusedPatBindWarn bind'
+ when (null bndrs && not ok_nobind_pat) $
+ addWarn (Reason Opt_WarnUnusedPatternBinds) $
+ unusedPatBindWarn bind'
; fvs' `seq` -- See Note [Free-variable space leak]
return (bind', bndrs, all_fvs) }
@@ -505,7 +506,24 @@ rnBind sig_fn (PatSynBind bind)
rnBind _ b = pprPanic "rnBind" (ppr b)
-{-
+{- Note [Pattern bindings that bind no variables]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Generally, we want to warn about pattern bindings like
+ Just _ = e
+because they don't do anything! But we have two exceptions:
+
+* A wildcard pattern
+ _ = rhs
+ which (a) is not that different from _v = rhs
+ (b) is sometimes used to give a type sig for,
+ or an occurrence of, a variable on the RHS
+
+* A strict patten binding; that is, one with an outermost bang
+ !Just _ = e
+ This can fail, so unlike the lazy variant, it is not a no-op.
+ Moreover, Trac #13646 argues that even for single constructor
+ types, you might want to write the constructor. See also #9127.
+
Note [Free-variable space leak]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We have