Commit 2707c4ea authored by Arnaud Spiwack's avatar Arnaud Spiwack Committed by Marge Bot
Browse files

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.
parent 51606236
......@@ -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) $
......
{-# LANGUAGE LinearTypes #-}
module LinearPatternGuardWildcard where
-- See #18439
unsafeConsume :: a #-> ()
unsafeConsume x | _ <- x = ()
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 = ()
......@@ -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, [''])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment