@@ -334,6 +334,7 @@ data PathElement v loc
334334 | InMatch loc -- location of 1st case body
335335 | InMatchGuard
336336 | InMatchBody
337+ | InActionRestriction
337338 deriving (Show )
338339
339340type ExpectedArgCount = Int
@@ -1275,7 +1276,7 @@ synthesizeWanted tm@(Term.Request' r) =
12751276synthesizeWanted (Term. Let1Top' top binding boundVarAnn e) = do
12761277 (tbinding, wb) <- synthesizeBinding top binding
12771278 v' <- ABT. freshen e freshenVar
1278- when (Var. isAction (ABT. variable e)) $
1279+ when (Var. isAction (ABT. variable e)) . scope InActionRestriction $
12791280 -- enforce that actions in a block have type ()
12801281 subtype tbinding (DDB. unitType (ABT. annotation binding))
12811282 appendContext [Ann v' boundVarAnn tbinding]
@@ -1428,7 +1429,9 @@ synthesizeWanted e
14281429 outputTypev <- freshenVar (Var. named " match-output" )
14291430 let outputType = existential' l B. Blank outputTypev
14301431 appendContext [existential outputTypev]
1431- cwant <- checkCases scrutineeType outputType cases
1432+ cwant <-
1433+ scope (InMatch (ABT. annotation outputType)) $
1434+ checkCases scrutineeType outputType cases
14321435 want <- coalesceWanted cwant swant
14331436 ctx <- getContext
14341437 let matchType = apply ctx outputType
@@ -1625,13 +1628,12 @@ checkCases ::
16251628 [Term. MatchCase loc (Term v loc )] ->
16261629 M v loc (Wanted v loc )
16271630checkCases _ _ [] = pure []
1628- checkCases scrutType outType cases@ (Term. MatchCase _ _ t : _) =
1629- scope (InMatch (ABT. annotation t)) $ do
1630- mes <- requestType (cases <&> \ (Term. MatchCase p _ _) -> p)
1631- for_ mes $ \ es ->
1632- applyM scrutType >>= \ sty -> ensureReqEffects sty es
1633- scrutType' <- applyM =<< ungeneralize scrutType
1634- coalesceWanteds =<< traverse (checkCase scrutType' outType) cases
1631+ checkCases scrutType outType cases = do
1632+ mes <- requestType (cases <&> \ (Term. MatchCase p _ _) -> p)
1633+ for_ mes $ \ es ->
1634+ applyM scrutType >>= \ sty -> ensureReqEffects sty es
1635+ scrutType' <- applyM =<< ungeneralize scrutType
1636+ coalesceWanteds =<< traverse (checkCase scrutType' outType) cases
16351637
16361638-- Checks a scrutinee type against a list of effects from e.g. a list of cases
16371639-- from a handler.
@@ -1970,8 +1972,10 @@ annotateLetRecBindings isTop letrec =
19701972 Foldable. for_ (zip3 vs bindings bindingTypes) $ \ (v, b, t) -> do
19711973 -- note: elements of a cycle have to be pure, otherwise order of effects
19721974 -- is unclear and chaos ensues
1975+
19731976 -- ensure actions in blocks have type ()
1974- when (Var. isAction v) $ subtype t (DDB. unitType (ABT. annotation b))
1977+ when (Var. isAction v) . scope InActionRestriction $
1978+ subtype t (DDB. unitType (ABT. annotation b))
19751979 insideDef v $ checkScopedWith b t []
19761980 ensureGuardedCycle (vs `zip` bindings)
19771981 pure (bindings, bindingTypes, vlocs)
@@ -2569,7 +2573,7 @@ checkWanted exact want (Term.Let1Top' top binding boundVarAnn m) t = do
25692573 want <- coalesceWanted wbinding want
25702574 v <- ABT. freshen m freshenVar
25712575 markThenRetractWanted v $ do
2572- when (Var. isAction (ABT. variable m)) $
2576+ when (Var. isAction (ABT. variable m)) . scope InActionRestriction $
25732577 -- enforce that actions in a block have type ()
25742578 subtype tbinding (DDB. unitType (ABT. annotation binding))
25752579 extendContext (Ann v boundVarAnn tbinding)
0 commit comments