Skip to content

Commit

Permalink
fix type of it variable when using type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
byorgey committed Jun 14, 2024
1 parent ba8d837 commit 5ac55d0
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/swarm-tui/Swarm/TUI/Controller.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ import Swarm.Language.Pretty
import Swarm.Language.Syntax hiding (Key)
import Swarm.Language.Typed (Typed (..))
import Swarm.Language.Types
import Swarm.Language.Value (Value (VExc, VKey, VUnit), envTypes, prettyValue)
import Swarm.Language.Value (Value (VExc, VKey, VUnit), envTydefs, envTypes, prettyValue)
import Swarm.Log
import Swarm.TUI.Controller.Util
import Swarm.TUI.Editor.Controller qualified as EC
Expand Down Expand Up @@ -837,7 +837,8 @@ updateUI = do
-- type, and reset the replStatus.
| otherwise -> do
itIx <- use (gameState . gameControls . replNextValueIndex)
let finalType = stripCmd pty
env <- use (gameState . baseEnv)
let finalType = stripCmd (env ^. envTydefs) pty
itName = fromString $ "it" ++ show itIx
out = T.intercalate " " [itName, ":", prettyText finalType, "=", into (prettyValue v)]
uiState . uiGameplay . uiREPL . replHistory %= addREPLItem (REPLOutput out)
Expand Down Expand Up @@ -982,11 +983,12 @@ doGoalUpdates = do

return goalWasUpdated

-- | Strips top-level `cmd` from type (in case of REPL evaluation),
-- and returns a boolean to indicate if it happened
stripCmd :: Polytype -> Polytype
stripCmd (Forall xs (TyCmd ty)) = Forall xs ty
stripCmd pty = pty
-- | Strips the top-level @Cmd@ from a type, if any (to compute the
-- result type of a REPL command evaluation).
stripCmd :: TDCtx -> Polytype -> Polytype
stripCmd tdCtx (Forall xs ty) = case whnfType tdCtx ty of
TyCmd resTy -> Forall xs resTy
_ -> Forall xs ty

------------------------------------------------------------
-- REPL events
Expand Down

0 comments on commit 5ac55d0

Please sign in to comment.