-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
Initally reported in fonsp/Pluto.jl#1973. When executing a simple block with a for loop in the REPL, the compiler will use isdefined(Main,s) which will have a side effect of implicitely importing the variable in Main and making impossible to assign to it in the given expression.
julia> begin
first = 1
for _ in false
first
end
end
ERROR: cannot assign a value to variable Base.first from module Main
Stacktrace:
[1] top-level scope
@ ./REPL[1]:2This is where I suspect the compiler uses isdefined(Main, :first) and isconst(Main, :first) for this given expression (from a gdb stacktrace):
julia/base/compiler/abstractinterpretation.jl
Lines 2001 to 2002 in 98b4b06
| if isdefined(M,s) | |
| if isconst(M,s) |
The issue is that isdefined(m, s) will resolve the binding and implicitely import it inside m as a side effect. The same is also true for isconst(m, s). Maybe their usage should not have this side-effect in this particular case ?