Skip to content

Commit 0e7d9ce

Browse files
committed
lowering: preserve handler order in (pop-handler-list ...)
This was reversing the list of handlers on accident.
1 parent 2943833 commit 0e7d9ce

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

src/julia-syntax.scm

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4436,15 +4436,16 @@ f(x) = yt(x)
44364436
(define (pop-handler-list src-tokens dest-tokens lab)
44374437
(if (eq? src-tokens dest-tokens)
44384438
#f
4439-
(let loop ((s src-tokens)
4440-
(l '()))
4441-
(if (not (pair? s))
4442-
(if (null? lab)
4443-
(error "Attempt to jump into catch block")
4444-
(error (string "cannot goto label \"" lab "\" inside try/catch block"))))
4445-
(if (eq? (cdr s) dest-tokens)
4446-
(cons (car s) l)
4447-
(loop (cdr s) (cons (car s) l))))))
4439+
(reverse
4440+
(let loop ((s src-tokens)
4441+
(l '()))
4442+
(if (not (pair? s))
4443+
(if (null? lab)
4444+
(error "Attempt to jump into catch block")
4445+
(error (string "cannot goto label \"" lab "\" inside try/catch block"))))
4446+
(if (eq? (cdr s) dest-tokens)
4447+
(cons (car s) l)
4448+
(loop (cdr s) (cons (car s) l)))))))
44484449
(define (emit-return tail x)
44494450
(define (emit- x)
44504451
(let* ((tmp (if ((if (null? catch-token-stack) valid-ir-return? simple-atom?) x)

test/syntax.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3865,6 +3865,29 @@ end
38653865
end
38663866
end
38673867

3868+
let src = Meta.@lower let
3869+
try
3870+
try
3871+
return 1
3872+
catch
3873+
end
3874+
finally
3875+
nothing
3876+
end
3877+
end
3878+
code = src.args[1].code
3879+
for stmt in code
3880+
if Meta.isexpr(stmt, :leave) && length(stmt.args) > 1
3881+
# Expr(:leave, ...) should list the arguments to pop from
3882+
# inner-most scope to outer-most
3883+
@test issorted(Int[
3884+
(arg::Core.SSAValue).id
3885+
for arg in stmt.args
3886+
]; rev=true)
3887+
end
3888+
end
3889+
end
3890+
38683891
# Test that globals can be `using`'d even if they are not yet defined
38693892
module UndefGlobal54954
38703893
global theglobal54954::Int

0 commit comments

Comments
 (0)