From 540fcf9920df93452f66c22b978cd9f297a0279f Mon Sep 17 00:00:00 2001 From: Brent Yorgey Date: Sat, 15 Jun 2024 23:48:57 -0500 Subject: [PATCH] bug fix: free vars in scope of tydef were being ignored; add minimal test case --- src/swarm-lang/Swarm/Language/Syntax/Util.hs | 2 +- test/unit/TestEval.hs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/swarm-lang/Swarm/Language/Syntax/Util.hs b/src/swarm-lang/Swarm/Language/Syntax/Util.hs index 9b839b2a12..16c303481c 100644 --- a/src/swarm-lang/Swarm/Language/Syntax/Util.hs +++ b/src/swarm-lang/Swarm/Language/Syntax/Util.hs @@ -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 @@ -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 diff --git a/test/unit/TestEval.hs b/test/unit/TestEval.hs index 265e62b56e..09f6affacc 100644 --- a/test/unit/TestEval.hs +++ b/test/unit/TestEval.hs @@ -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