Skip to content

Commit

Permalink
Merge new requirements context with existing when running from REPL (#…
Browse files Browse the repository at this point in the history
…965)

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.
  • Loading branch information
byorgey authored Jan 5, 2023
1 parent 508d21d commit 3f5b7ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Swarm/TUI/Controller.hs
Original file line number Diff line number Diff line change
Expand Up @@ -830,13 +830,13 @@ 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
-- 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.
Expand Down
6 changes: 3 additions & 3 deletions test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -249,10 +249,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
Expand Down

0 comments on commit 3f5b7ff

Please sign in to comment.