You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This function normally fails, because b is not defined in the second iteration of the loop.
functionfoo()
a =1for i =1:2if i ==1
b =10else
a = b
endendreturn a +1end
However, in debug mode (e.g. @run foo()) it does not fail, since bis defined when the offending line is to be run:
julia>@breakpointfoo() 7foo() in Main at /home/meliana/prueba/test.jl:1:7
julia>@runfoo()
Hit breakpoint:
In foo() at /home/meliana/prueba/test.jl:13for i =1:24if i ==15 b =106else>7 a = b
8end9end10return a +111end
About to run: _J5
1|debug> fr
[1] foo() at /home/meliana/prueba/test.jl:1| a::Int64=1|::Tuple{Int64,Int64}= (2, 2)
| i::Int64=2| b::Int64=10
If I understand it right, this seems to be happening because in the first iteration b got into the running frame, and while the interpreter is inside the loop, it takes the values for its local variables (including b) from the frame.
On the other hand, that's not happening here:
functionbar()
let
a =1endreturn a +1end
julia>@enterbar()
In bar() at /home/meliana/prueba/test.jl:11functionbar()
2let3 a =14end>5return a +16end
About to run: (+)(Main.a, 1)
1|debug> fr
[1] bar() at /home/meliana/prueba/test.jl:1| a::Int64=11|debug> c
ERROR: UndefVarError: a not defined
Stacktrace:
[1] bar() at /home/meliana/prueba/test.jl:5
In this second example, the variable a also remains in the frame after exiting the let block, but since the last line is outside the part of the code that contains its scope, the interpreter does not look for the value of a in the frame anymore (thus the line "about to run" refers to Main.a).
The text was updated successfully, but these errors were encountered:
(Detected here: https://discourse.julialang.org/t/running-tests-vs-debugging-gives-different-results/52554)
This function normally fails, because
b
is not defined in the second iteration of the loop.However, in debug mode (e.g.
@run foo()
) it does not fail, sinceb
is defined when the offending line is to be run:If I understand it right, this seems to be happening because in the first iteration
b
got into the running frame, and while the interpreter is inside the loop, it takes the values for its local variables (includingb
) from the frame.On the other hand, that's not happening here:
In this second example, the variable
a
also remains in the frame after exiting thelet
block, but since the last line is outside the part of the code that contains its scope, the interpreter does not look for the value ofa
in the frame anymore (thus the line "about to run" refers toMain.a
).The text was updated successfully, but these errors were encountered: