A peer-to-peer stack for code collaboration
Fixes #191 in which catch did not correctly handle the scope of the handler
Luke Palmerecc097e4650d
diff --git a/rad/prelude.rad b/rad/prelude.radindex f43cf14..70894d8 100644--- a/rad/prelude.rad+++ b/rad/prelude.rad@@ -6,6 +6,7 @@(load! "rad/prelude/dict.rad")(load! "rad/prelude/ref.rad")(load! "rad/prelude/lens.rad")+(load! "rad/prelude/exception.rad")(load! "rad/chain.rad")(load! "rad/state-machine.rad")@@ -18,6 +19,7 @@"rad/prelude/dict.rad""rad/prelude/ref.rad""rad/prelude/lens.rad"+ "rad/prelude/exception.rad""rad/state-machine.rad"))diff --git a/rad/prelude/exception.rad b/rad/prelude/exception.radnew file mode 100644index 0000000..f721782--- /dev/null+++ b/rad/prelude/exception.rad@@ -0,0 +1,5 @@+(should-be "catch handles scope correctly"+ ;; Issue #191, catch used to accidentally use the lexical environment of+ ;; the `throw` that generated the exception.+ ((fn [body handler] (catch 'any (body) handler)) (fn [] (throw 'foo "foo")) (fn [e] #t))+ #t)diff --git a/src/Radicle/Internal/Core.hs b/src/Radicle/Internal/Core.hsindex 359760f..8bc1bed 100644--- a/src/Radicle/Internal/Core.hs+++ b/src/Radicle/Internal/Core.hs@@ -468,12 +468,13 @@ specialForms = Map.fromList $ first Ident <$>, ("catch", \case[l, form, handler] -> domlabel <- baseEval l+ handlerclo <- baseEval handlercase mlabel of-- TODO reify stackAtom label -> baseEval form `catchError` \(LangError _stack e) -> do(thrownLabel, thrownValue) <- errorDataToValue eif thrownLabel == label || label == Ident "any"- then handler $$ [thrownValue]+ then handlerclo $$ [thrownValue]else baseEval form_ -> throwErrorHere $ TypeError "catch: first argument must be atom"xs -> throwErrorHere $ WrongNumberOfArgs "catch" 3 (length xs))