Skip to content

Commit

Permalink
bug fix: free vars in scope of tydef were being ignored; add minimal …
Browse files Browse the repository at this point in the history
…test case
  • Loading branch information
byorgey committed Jun 16, 2024
1 parent c903d79 commit 540fcf9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/swarm-lang/Swarm/Language/Syntax/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ freeVarsS f = go S.empty
TRef {} -> pure s
TRequireDevice {} -> pure s
TRequire {} -> pure s
STydef {} -> pure s
SRequirements x s1 -> rewrap $ SRequirements x <$> go bound s1
TVar x
| x `S.member` bound -> pure s
Expand All @@ -138,6 +137,7 @@ freeVarsS f = go S.empty
SLet ls r x xty xreq s1 s2 ->
let bound' = S.insert (lvVar x) bound
in rewrap $ SLet ls r x xty xreq <$> go bound' s1 <*> go bound' s2
STydef x xdef tdInfo t1 -> rewrap $ STydef x xdef tdInfo <$> go bound t1
SPair s1 s2 -> rewrap $ SPair <$> go bound s1 <*> go bound s2
SBind mx mty mpty mreq s1 s2 -> rewrap $ SBind mx mty mpty mreq <$> go bound s1 <*> go (maybe id (S.insert . lvVar) mx bound) s2
SDelay m s1 -> rewrap $ SDelay m <$> go bound s1
Expand Down
3 changes: 3 additions & 0 deletions test/unit/TestEval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ testEval g =
`evaluatesTo` VInt 5
)
]
, testCase
"tydef does not prevent forcing of recursive variables"
("def forever = \\c. c; forever c end; tydef X = Int end; def go = forever move end" `evaluatesTo` VUnit)
]
where
tquote :: String -> Text
Expand Down

0 comments on commit 540fcf9

Please sign in to comment.