Open turtleslow opened 8 years ago
This is essentially #265
Reduced code is
module A
export px
const px = ""
end
using A
type B
value::Float64
B(v::Float64) = new(v)
end
begin
px = 1.0
println(px, ", ", typeof(px))
b = B(px)
for ii=1:1 #no error if loop is removed
end
end
The dummy loop triggers the compilation heuristic which compiles the whole body for the imported px
.
It's not #265, although it has been making my PR for #265 harder and less accurate.
Updating the reduced example for modern syntax
module A
export px
const px = ""
end
using .A
struct B
value::Float64
B(v::Float64) = new(v)
end
begin
px = 1.0
println(px, ", ", typeof(px))
b = B(px)
for ii=1:1 #no error if loop is removed
end
end
it looks like this does still happen today (1.8.3 and 1.9.0-alpha1), except the error is now:
julia> begin
px = 1.0
println(px, ", ", typeof(px))
b = B(px)
for ii=1:1 #no error if loop is removed
end
end
ERROR: cannot assign a value to variable A.px from module Main
Stacktrace:
[1] top-level scope
@ ./REPL[4]:2
whereas no error if run in a fresh session without the loop:
julia> begin
px = 1.0
println(px, ", ", typeof(px))
b = B(px)
end
1.0, Float64
B(1.0)
Running the following in a fresh session:
returns:
Note that I must have the following to create this error: 1) It must be a new Julia session 2 )The if statement must be there 3) The for loop must be there
My
versioninfo()
is:The code does not throw an error on jupyter (v 3.2). I understand Gadfly.px has type Measures.Length{:mm,Float64}, but I have not been able to replicate this without using Gadfly in trying to narrow down the cause of the issue.