Skip to content

Commit 0a4701f

Browse files
committed
Allow try-catches to take non-lists in body
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 #30.
1 parent d30d9f5 commit 0a4701f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/built-in-macros.ls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ contents =
361361
\try : ({compile, compile-many}:env, ...args) ->
362362

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

test.ls

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,23 @@ test "try-catch (with `catch` and `finally`)" ->
406406
}
407407
"""
408408

409+
test "try-catch (with plain atom in body)" ->
410+
esl '''
411+
(try foo
412+
(catch e
413+
bar)
414+
(finally baz))
415+
'''
416+
..`@equals` """
417+
try {
418+
foo;
419+
} catch (e) {
420+
bar;
421+
} finally {
422+
baz;
423+
}
424+
"""
425+
409426
test "try-catch (with empty body, `catch` and `finally`)" ->
410427
esl '''
411428
(try (catch err)

0 commit comments

Comments
 (0)