[Git][ghc/ghc][master] Pattern guards BindStmt always use multiplicity Many
Marge Bot
gitlab at gitlab.haskell.org
Sat Sep 26 01:14:05 UTC 2020
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
2707c4ea by Arnaud Spiwack at 2020-09-25T21:13:58-04:00
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.
- - - - -
4 changed files:
- compiler/GHC/Tc/Gen/Match.hs
- + testsuite/tests/linear/should_fail/LinearPatternGuardWildcard.hs
- + testsuite/tests/linear/should_fail/LinearPatternGuardWildcard.stderr
- testsuite/tests/linear/should_fail/all.T
Changes:
=====================================
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) $
=====================================
testsuite/tests/linear/should_fail/LinearPatternGuardWildcard.hs
=====================================
@@ -0,0 +1,7 @@
+{-# LANGUAGE LinearTypes #-}
+module LinearPatternGuardWildcard where
+
+-- See #18439
+
+unsafeConsume :: a #-> ()
+unsafeConsume x | _ <- x = ()
=====================================
testsuite/tests/linear/should_fail/LinearPatternGuardWildcard.stderr
=====================================
@@ -0,0 +1,5 @@
+
+LinearPatternGuardWildcard.hs:7:15: error:
+ • Couldn't match type ‘'Many’ with ‘'One’
+ arising from multiplicity of ‘x’
+ • In an equation for ‘unsafeConsume’: unsafeConsume x | _ <- x = ()
=====================================
testsuite/tests/linear/should_fail/all.T
=====================================
@@ -27,3 +27,4 @@ test('LinearPolyType', expect_broken([436, broken_multiplicity_syntax]), compile
test('LinearBottomMult', normal, compile_fail, [''])
test('LinearSequenceExpr', normal, compile_fail, [''])
test('LinearIf', normal, compile_fail, [''])
+test('LinearPatternGuardWildcard', normal, compile_fail, [''])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2707c4eae4cf99e6da2709e128f560d91e468357
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2707c4eae4cf99e6da2709e128f560d91e468357
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200925/cb7bdb45/attachment-0001.html>
More information about the ghc-commits
mailing list