Skip to content

Commit

Permalink
sml: fix mlton self-host. Full syntax err in catch*
Browse files Browse the repository at this point in the history
In mlton mode, syntax errors caught in the try/catch block were being
processed as "SyntaxError" without any additional context/message.
Explicitly pass the full message always.

Add a step9 test that tries to catch a syntax error and make sure that
it has one of the syntax error message (i.e. that will be expected when
running self-host of step1).
  • Loading branch information
kanaka committed Aug 20, 2024
1 parent a160866 commit 4719e58
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions impls/sml/step9_try.sml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ and evalTry e [a, LIST ([SYMBOL "catch*", b, c],_)] = (eval e a handle ex => eva
and evalCatch e b ex body = eval (bind [b, exnVal ex] e) body

and exnVal (MalException x) = x
| exnVal (SyntaxError msg) = STRING msg
| exnVal (NotDefined msg) = STRING msg
| exnVal (NotApplicable msg) = STRING msg
| exnVal (OutOfBounds msg) = STRING msg
Expand Down
1 change: 1 addition & 0 deletions impls/sml/stepA_mal.sml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ and evalTry e [a, LIST ([SYMBOL "catch*", b, c],_)] = (eval e a handle ex => eva
and evalCatch e b ex body = eval (bind [b, exnVal ex] e) body

and exnVal (MalException x) = x
| exnVal (SyntaxError msg) = STRING msg
| exnVal (NotDefined msg) = STRING msg
| exnVal (NotApplicable msg) = STRING msg
| exnVal (OutOfBounds msg) = STRING msg
Expand Down
4 changes: 4 additions & 0 deletions impls/tests/step9_try.mal
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
(try* (map throw (list "my err")) (catch* exc exc))
;=>"my err"

;; Test catch of reader errors
(try* (eval (read-string "(+ 1")) (catch* e (prn :e e)))
;/.*(EOF|end of input|unbalanced).*


;;
;; Testing builtin functions
Expand Down

0 comments on commit 4719e58

Please sign in to comment.