Skip to content

Commit 35ac635

Browse files
authored
fix exception stack pop for UndefVarError in catch block (#37269)
1 parent dca2548 commit 35ac635

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/julia-syntax.scm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3780,7 +3780,9 @@ f(x) = yt(x)
37803780
(let* ((x (if rett
37813781
(compile (convert-for-type-decl x rett) '() #t #f)
37823782
x))
3783-
(tmp (if (valid-ir-return? x) #f (make-ssavalue))))
3783+
(tmp (if ((if (null? catch-token-stack) valid-ir-return? simple-atom?) x)
3784+
#f
3785+
(make-ssavalue))))
37843786
(if tmp (emit `(= ,tmp ,x)))
37853787
(let ((pexc (pop-exc-expr catch-token-stack '())))
37863788
(if pexc (emit pexc)))

test/exceptions.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,18 @@ function f36527()
383383
end
384384

385385
@test f36527()
386+
387+
# accessing an undefined var in tail position in a catch block
388+
function undef_var_in_catch()
389+
try
390+
error("first error")
391+
catch
392+
__probably_n0t_defined__
393+
end
394+
end
395+
@test length(try
396+
undef_var_in_catch()
397+
[]
398+
catch
399+
catch_stack()
400+
end) == 2

0 commit comments

Comments
 (0)