summaryrefslogtreecommitdiff
path: root/compiler/GHC
diff options
context:
space:
mode:
authorArnaud Spiwack <arnaud.spiwack@tweag.io>2020-09-23 12:20:46 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-09-25 21:13:58 -0400
commit2707c4eae4cf99e6da2709e128f560d91e468357 (patch)
tree729acd98bb114b7e799995a4d7bdc6b0fb7f1e59 /compiler/GHC
parent516062366ed1957e499f27dfc6b685a073a18400 (diff)
downloadhaskell-2707c4eae4cf99e6da2709e128f560d91e468357.tar.gz
Pattern guards BindStmt always use multiplicity Many
Fixes #18439 . The rhs of the pattern guard was consumed with multiplicity one, while the pattern assumed it was Many. We use Many everywhere instead. This is behaviour consistent with that of `case` expression. See #18738.
Diffstat (limited to 'compiler/GHC')
-rw-r--r--compiler/GHC/Tc/Gen/Match.hs9
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/GHC/Tc/Gen/Match.hs b/compiler/GHC/Tc/Gen/Match.hs
index 30fe0cad44..38e400419a 100644
--- a/compiler/GHC/Tc/Gen/Match.hs
+++ b/compiler/GHC/Tc/Gen/Match.hs
@@ -397,7 +397,14 @@ tcGuardStmt _ (BodyStmt _ guard _ _) res_ty thing_inside
; return (BodyStmt boolTy guard' noSyntaxExpr noSyntaxExpr, thing) }
tcGuardStmt ctxt (BindStmt _ pat rhs) res_ty thing_inside
- = do { (rhs', rhs_ty) <- tcInferRhoNC rhs
+ = do { -- The Many on the next line and the unrestricted on the line after
+ -- are linked. These must be the same multiplicity. Consider
+ -- x <- rhs -> u
+ --
+ -- The multiplicity of x in u must be the same as the multiplicity at
+ -- which the rhs has been consumed. When solving #18738, we want these
+ -- two multiplicity to still be the same.
+ (rhs', rhs_ty) <- tcScalingUsage Many $ tcInferRhoNC rhs
-- Stmt has a context already
; (pat', thing) <- tcCheckPat_O (StmtCtxt ctxt) (lexprCtOrigin rhs)
pat (unrestricted rhs_ty) $