Skip to content

Commit 56f4222

Browse files
authored
fix exception type for undefined variables (#249)
1 parent a974c71 commit 56f4222

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/interpret.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ lookup_var(frame, ref::GlobalRef) = getfield(ref.mod, ref.name)
1010
function lookup_var(frame, slot::SlotNumber)
1111
val = frame.framedata.locals[slot.id]
1212
val !== nothing && return val.value
13-
error("slot ", slot, " with name ", frame.framecode.src.slotnames[slot.id], " not assigned")
13+
throw(UndefVarError(frame.framecode.src.slotnames[slot.id]))
1414
end
1515

1616
function lookup_expr(frame, e::Expr)

test/interpret.jl

+5-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ f113(;x) = x
336336
end
337337
frame = JuliaInterpreter.enter_call(f_multi, 1)
338338
nlocals = length(frame.framedata.locals)
339-
@test_throws ErrorException("slot _4 with name x not assigned") JuliaInterpreter.lookup_var(frame, Core.SlotNumber(nlocals))
339+
@test_throws UndefVarError JuliaInterpreter.lookup_var(frame, Core.SlotNumber(nlocals))
340340
stack = [frame]
341341
locals = JuliaInterpreter.locals(frame)
342342
@test length(locals) == 2
@@ -500,3 +500,7 @@ function f_mmap()
500500
end
501501
end
502502
@interpret f_mmap()
503+
504+
# Test exception type for undefined variables
505+
f() = s = s + 1
506+
@test_throws UndefVarError @interpret f()

0 commit comments

Comments
 (0)