From b4e37b40a4fcdc1a4585234fb4ba066fbdc78815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C5=A0ebek?= Date: Fri, 10 Jun 2022 17:29:15 +0200 Subject: [PATCH] Disallow cardinal diretion values without compass --- src/Swarm/Game/Step.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Swarm/Game/Step.hs b/src/Swarm/Game/Step.hs index b338ca16c..d158797d4 100644 --- a/src/Swarm/Game/Step.hs +++ b/src/Swarm/Game/Step.hs @@ -374,10 +374,19 @@ stepCESK cesk = case cesk of -- Now some straightforward cases. These all immediately turn -- into values. In TUnit _ s k -> return $ Out VUnit s k - In (TDir d) _ s k -> return $ Out (VDir d) s k In (TInt n) _ s k -> return $ Out (VInt n) s k In (TString str) _ s k -> return $ Out (VString str) s k In (TBool b) _ s k -> return $ Out (VBool b) s k + -- Direction is simple too unless it is absolute (e.g. north) + -- and needs orient capability (provided by a compass). + -- This may be redundant just because of base escaping + -- capability checking (see #231). + In (TDir d) _ s k -> do + orient <- hasCapability COrient + if isCardinal d && not orient + then return $ Up (Incapable (S.singleton COrient) (TDir d)) s [] + else return $ Out (VDir d) s k + -- There should not be any antiquoted variables left at this point. In (TAntiString v) _ s k -> return $ Up (Fatal (T.append "Antiquoted variable found at runtime: $str:" v)) s k @@ -1391,7 +1400,7 @@ execConst c vs s k = do [VBool b] -> return $ Out (VBool (not b)) s k _ -> badConst Neg -> case vs of - [VInt n] -> return $ Out (VInt (- n)) s k + [VInt n] -> return $ Out (VInt (-n)) s k _ -> badConst Eq -> returnEvalCmp Neq -> returnEvalCmp