File tree Expand file tree Collapse file tree 2 files changed +10
-16
lines changed Expand file tree Collapse file tree 2 files changed +10
-16
lines changed Original file line number Diff line number Diff line change 1515
1515
(cond
1516
1516
((eq? nxt 'end )
1517
1517
(list* 'try try-block (or catchv ' (false))
1518
- (or catchb (if ( or finalb elseb) ' (false) (error " try without catch, else or finally" )))
1518
+ (or catchb (if finalb ' (false) (error " try without catch or finally" )))
1519
1519
(cond (elseb (list (or finalb ' (false)) elseb))
1520
1520
(finalb (list finalb))
1521
1521
(else '() ))))
1561
1561
elseb)))
1562
1562
((and (eq? nxt 'else )
1563
1563
(not elseb))
1564
+ (if (or (not catchb) finalb)
1565
+ (error " else inside try block needs to be immediately after catch" ))
1564
1566
(let ((eb (if (eq? (require-token s) ' (catch finally))
1565
1567
' (block)
1566
1568
(parse-block s))))
Original file line number Diff line number Diff line change @@ -2983,9 +2983,15 @@ end
2983
2983
@test fails (error)
2984
2984
@test ! fails (() -> 1 + 2 )
2985
2985
2986
+ @test_throws ParseError Meta. parse (" try foo() else bar() end" )
2987
+ @test_throws ParseError Meta. parse (" try foo() else bar() catch; baz() end" )
2988
+ @test_throws ParseError Meta. parse (" try foo() catch; baz() finally foobar() else bar() end" )
2989
+ @test_throws ParseError Meta. parse (" try foo() finally foobar() else bar() catch; baz() end" )
2990
+
2986
2991
err = try
2987
2992
try
2988
2993
1 + 2
2994
+ catch
2989
2995
else
2990
2996
error (" foo" )
2991
2997
end
@@ -2998,6 +3004,7 @@ end
2998
3004
err = try
2999
3005
try
3000
3006
1 + 2
3007
+ catch
3001
3008
else
3002
3009
error (" foo" )
3003
3010
finally
@@ -3009,21 +3016,6 @@ end
3009
3016
@test err == ErrorException (" foo" )
3010
3017
@test x == 1
3011
3018
3012
- x = 0
3013
- err = try
3014
- try
3015
- 1 + 2
3016
- else
3017
- 3 + 4
3018
- finally
3019
- x += 1
3020
- end
3021
- catch e
3022
- e
3023
- end
3024
- @test err == 3 + 4
3025
- @test x == 1
3026
-
3027
3019
x = 0
3028
3020
err = try
3029
3021
try
You can’t perform that action at this time.
0 commit comments