Skip to content

Commit

Permalink
Allow try-catches to take non-lists in body
Browse files Browse the repository at this point in the history
The routine detecting the catch and finally parts was assuming its
inputs are always lists, leading to errors when passed an atom or
string.

Fixes anko#30.
  • Loading branch information
anko committed Oct 22, 2015
1 parent d30d9f5 commit 0a4701f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/built-in-macros.ls
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ contents =
\try : ({compile, compile-many}:env, ...args) ->

is-part = (thing, clause-name) ->
if not (thing instanceof list) then return false
first = thing.content.0
(first instanceof atom) && (first.text! is clause-name)

Expand Down
17 changes: 17 additions & 0 deletions test.ls
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,23 @@ test "try-catch (with `catch` and `finally`)" ->
}
"""

test "try-catch (with plain atom in body)" ->
esl '''
(try foo
(catch e
bar)
(finally baz))
'''
..`@equals` """
try {
foo;
} catch (e) {
bar;
} finally {
baz;
}
"""

test "try-catch (with empty body, `catch` and `finally`)" ->
esl '''
(try (catch err)
Expand Down

0 comments on commit 0a4701f

Please sign in to comment.