From db01ee81fd01eb27725d643b587813c65bef3011 Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Fri, 15 Feb 2019 11:50:39 +0100 Subject: [PATCH] slightly better line numbers --- src/interpret.jl | 6 ++++-- test/interpret.jl | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/interpret.jl b/src/interpret.jl index bb2c3a6cafc5d..442ce52647da5 100644 --- a/src/interpret.jl +++ b/src/interpret.jl @@ -566,8 +566,10 @@ isgotonode(node) = isa(node, GotoNode) || isexpr(node, :gotoifnot) location(frame) = location(frame, frame.pc[]) function location(frame, pc) - ln = frame.code.code.codelocs[pc.next_stmt] - return frame.code.scope isa Method ? ln + frame.code.scope.line - 1 : ln + codeloc = frame.code.code.codelocs[pc.next_stmt] + return frame.code.scope isa Method ? + frame.code.code.linetable[codeloc].line : + codeloc end function next_line!(stack, frame, dbstack = nothing) initial = location(frame) diff --git a/test/interpret.jl b/test/interpret.jl index 5b6432e1fb8b4..8442d08ed0ab2 100644 --- a/test/interpret.jl +++ b/test/interpret.jl @@ -196,3 +196,18 @@ JuliaInterpreter.finish_and_return!(JuliaStackFrame[], frame, true) val = @interpret(BigInt()) @test isa(val, BigInt) && val == 0 @test isa(@interpret(Base.GMP.version()), VersionNumber) + +# "correct" line numbers +defline = @__LINE__() + 1 +function f(x) + x = 2x + # comment + # comment + x = 2x + # comment + return x*x +end +frame = JuliaInterpreter.enter_call(f, 3) +@test JuliaInterpreter.location(frame, JuliaInterpreter.JuliaProgramCounter(1)) == defline + 1 +@test JuliaInterpreter.location(frame, JuliaInterpreter.JuliaProgramCounter(3)) == defline + 4 +@test JuliaInterpreter.location(frame, JuliaInterpreter.JuliaProgramCounter(5)) == defline + 6