First, I created a file named DictTest.jl
with the following content:
module DictTest
data = Dict(GlobalRef(Base,:sum) => GlobalRef(Base,:prod),
1 => GlobalRef(Base,:sum))
end
and put the file into the JULIA_LOAD_PATH
.
Then in REPL:
julia> using DictTest
[ Info: Precompiling DictTest [top-level]
julia> DictTest.data
Dict{Any,GlobalRef} with 2 entries:
:(Base.sum) => :(Base.prod)
1 => :(Base.sum)
julia> DictTest.data[1]
:(Base.sum)
julia> DictTest.data[GlobalRef(Base,:sum)]
ERROR: KeyError: key :(Base.sum) not found
Stacktrace:
[1] getindex(::Dict{Any,GlobalRef}, ::GlobalRef) at .\dict.jl:467
[2] top-level scope at none:1
julia> DictTest.data.keys[10]
:(Base.sum)
julia> DictTest.data[DictTest.data.keys[10]]
ERROR: KeyError: key :(Base.sum) not found
Stacktrace:
[1] getindex(::Dict{Any,GlobalRef}, ::GlobalRef) at .\dict.jl:467
[2] top-level scope at none:1
The last result make me crazy.
Restart Julia, and
julia> cd(ENV["JULIA_LOAD_PATH"][1:end-1])
julia> include("DictTest.jl")
Main.DictTest
julia> DictTest.data[1]
:(Base.sum)
julia> DictTest.data[GlobalRef(Base,:sum)]
:(Base.prod)
It seem using
gives a wrong result while include
is ok. I have little knowledge about Julia’s pre-compile, is this a feature or a bug?
Here’s the versioninfo:
Julia Version 1.5.1
Commit 697e782ab8 (2020-08-25 20:08 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i5-9600KF CPU @ 3.70GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-9.0.1 (ORCJIT, skylake)