Skip to content

Commit 3a71916

Browse files
committed
fix accessing undef sparam
1 parent ad58eb9 commit 3a71916

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/interpret.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ end
1616
function lookup_expr(frame, e::Expr)
1717
head = e.head
1818
head == :the_exception && return frame.framedata.last_exception[]
19-
head == :static_parameter && return frame.framedata.sparams[e.args[1]::Int]
19+
if head == :static_parameter
20+
arg = e.args[1]::Int
21+
if isassigned(frame.framedata.sparams, arg)
22+
return frame.framedata.sparams[arg]
23+
else
24+
syms = sparam_syms(frame.framecode.scope)
25+
throw(UndefVarError(syms[arg]))
26+
end
27+
end
2028
head == :boundscheck && length(e.args) == 0 && return true
2129
error("invalid lookup expr ", e)
2230
end

test/interpret.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,15 @@ file, line = JuliaInterpreter.whereis(fr)
401401
@test isfile(file)
402402
@test isfile(JuliaInterpreter.getfile(fr.framecode.src.linetable[1]))
403403
@test occursin(Sys.STDLIB, repr(fr))
404+
405+
# Test undef sparam (https://github.com/JuliaDebug/JuliaInterpreter.jl/issues/165)
406+
function foo(x::T) where {T <: AbstractString, S <: AbstractString}
407+
return S
408+
end
409+
e = try
410+
@interpret foo("")
411+
catch err
412+
err
413+
end
414+
@test e isa UndefVarError
415+
@test e.var == :S

0 commit comments

Comments
 (0)