Skip to content

Commit

Permalink
fix exception type for undefined variables (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC authored Mar 31, 2019
1 parent a974c71 commit 56f4222
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ lookup_var(frame, ref::GlobalRef) = getfield(ref.mod, ref.name)
function lookup_var(frame, slot::SlotNumber)
val = frame.framedata.locals[slot.id]
val !== nothing && return val.value
error("slot ", slot, " with name ", frame.framecode.src.slotnames[slot.id], " not assigned")
throw(UndefVarError(frame.framecode.src.slotnames[slot.id]))
end

function lookup_expr(frame, e::Expr)
Expand Down
6 changes: 5 additions & 1 deletion test/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ f113(;x) = x
end
frame = JuliaInterpreter.enter_call(f_multi, 1)
nlocals = length(frame.framedata.locals)
@test_throws ErrorException("slot _4 with name x not assigned") JuliaInterpreter.lookup_var(frame, Core.SlotNumber(nlocals))
@test_throws UndefVarError JuliaInterpreter.lookup_var(frame, Core.SlotNumber(nlocals))
stack = [frame]
locals = JuliaInterpreter.locals(frame)
@test length(locals) == 2
Expand Down Expand Up @@ -500,3 +500,7 @@ function f_mmap()
end
end
@interpret f_mmap()

# Test exception type for undefined variables
f() = s = s + 1
@test_throws UndefVarError @interpret f()

0 comments on commit 56f4222

Please sign in to comment.