From fe2c9cbbbcd771ebd67e93aa68eda265198e5375 Mon Sep 17 00:00:00 2001 From: Brent Yorgey Date: Thu, 5 Jan 2023 13:53:18 -0600 Subject: [PATCH 1/2] Merge new requirements context with existing when running from REPL Fixes #964. Unfortunately I don't know of any way to make a test for this. Part of the reason we went so long without noticing is that it only specifically affected the code path for running terms from the REPL, and tests can never run that code. --- src/Swarm/TUI/Controller.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Swarm/TUI/Controller.hs b/src/Swarm/TUI/Controller.hs index adb58afa3..777525a07 100644 --- a/src/Swarm/TUI/Controller.hs +++ b/src/Swarm/TUI/Controller.hs @@ -836,7 +836,7 @@ handleREPLEventTyping = \case -- `reprogram` at runtime. See the discussion at -- https://github.com/swarm-game/swarm/pull/827 for more -- details. - . (gameState . baseRobot . robotContext . defReqs .~ reqCtx) + . (gameState . baseRobot . robotContext . defReqs <>~ reqCtx) -- Set up the robot's CESK machine to evaluate/execute the -- given term, being sure to initialize the CESK machine -- environment and store from the top-level context. From dcbbe3c8eebae9b4e48dba0da5b937acb5081172 Mon Sep 17 00:00:00 2001 From: Brent Yorgey Date: Thu, 5 Jan 2023 14:45:05 -0600 Subject: [PATCH 2/2] comment tweaks, and merge instead of set reqCtx in integration tests also --- src/Swarm/TUI/Controller.hs | 2 +- test/integration/Main.hs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Swarm/TUI/Controller.hs b/src/Swarm/TUI/Controller.hs index 777525a07..93b8f9cef 100644 --- a/src/Swarm/TUI/Controller.hs +++ b/src/Swarm/TUI/Controller.hs @@ -830,7 +830,7 @@ handleREPLEventTyping = \case -- term (by `def` statements) to their requirements. -- E.g. if we had `def m = move end`, the reqCtx would -- record the fact that `m` needs the `move` capability. - -- We simply dump the entire `reqCtx` into the robot's + -- We simply add the entire `reqCtx` to the robot's -- context, so we can look up requirements if we later -- need to requirements-check an argument to `build` or -- `reprogram` at runtime. See the discussion at diff --git a/test/integration/Main.hs b/test/integration/Main.hs index 6751c1708..9f8e497fb 100644 --- a/test/integration/Main.hs +++ b/test/integration/Main.hs @@ -5,7 +5,7 @@ -- | Swarm integration tests module Main where -import Control.Lens (Ixed (ix), to, use, view, (&), (.~), (<&>), (^.), (^..), (^?!)) +import Control.Lens (Ixed (ix), to, use, view, (&), (.~), (<&>), (<>~), (^.), (^..), (^?!)) import Control.Monad (filterM, forM_, unless, void, when) import Control.Monad.State (StateT (runStateT), gets) import Control.Monad.Trans.Except (runExceptT) @@ -248,10 +248,10 @@ testScenarioSolution _ci _em = Just sol@(ProcessedTerm _ _ _ reqCtx) -> do let gs' = gs - -- See #827 for an explanation of why it's important to set + -- See #827 for an explanation of why it's important to add to -- the robotContext defReqs here (and also why this will, -- hopefully, eventually, go away). - & baseRobot . robotContext . defReqs .~ reqCtx + & baseRobot . robotContext . defReqs <>~ reqCtx & baseRobot . machine .~ initMachine sol Ctx.empty emptyStore m <- timeout (time s) (snd <$> runStateT playUntilWin gs') case m of