Skip to content

Commit

Permalink
requirements analysis for literal argument to use
Browse files Browse the repository at this point in the history
  • Loading branch information
byorgey committed Nov 17, 2024
1 parent 0ee5d52 commit 7d61996
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/swarm-lang/Swarm/Language/Requirements/Analysis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ requirements tdCtx ctx =
add (singletonCap CLambda)
mapM_ typeRequirements mty
local @ReqCtx (Ctx.delete x) $ go t
-- An application simply requires the union of the capabilities
-- from the left- and right-hand sides. This assumes that the
-- argument will be used at least once by the function.
-- Special case for 'use' with a device literal.
TApp (TConst Use) (TText device) -> add (singletonDev device)
-- In general, an application simply requires the union of the
-- capabilities from the left- and right-hand sides. This assumes
-- that the argument will be used at least once by the function.
TApp t1 t2 -> go t1 *> go t2
-- Similarly, for a let, we assume that the let-bound expression
-- will be used at least once in the body. We delete the let-bound
Expand Down
8 changes: 8 additions & 0 deletions test/unit/TestRequirements.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ testRequirements =
"def m = move end; def y = \\m. log (format m) end"
(maybe False ((CExecute Move `S.notMember`) . capReqs) . Ctx.lookup "y")
]
, testGroup
"use"
[ testCase "literal argument to use (#1301)" $
"use \"key\"" `requiresDev` "key"
]
]

checkReqCtx :: Text -> (ReqCtx -> Bool) -> Assertion
Expand All @@ -49,3 +54,6 @@ checkRequirements code expect = check code (expect . requirements mempty mempty

requiresCap :: Text -> Capability -> Assertion
requiresCap code cap = checkRequirements code ((cap `S.member`) . capReqs)

requiresDev :: Text -> Text -> Assertion
requiresDev code dev = checkRequirements code ((dev `S.member`) . capDevs)

Check failure on line 59 in test/unit/TestRequirements.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - windows-latest - ghc-9.8.2

Variable not in scope: capDevs :: Requirements -> S.Set Text

0 comments on commit 7d61996

Please sign in to comment.