Skip to content

compiling top-level expressions forces global binding resolution #14055

@315234

Description

@315234

Sorry the title is so vague but I can't get my head around what is happening here. Minimal code which reproduces this bug:

if true # required to exhibit bug
    upper = ones(4)
    lower = ones(4)

    # WARNING: imported binding overwritten
    # required to exhibit bug
    diag  = ones(5)

    A = Tridiagonal(lower,diag,upper)

    for i=1:10 # required to exhibit bug
    end
end

Output:

$ julia --version
julia version 0.4.0

$ julia bug.jl
WARNING: imported binding for diag overwritten in module Main
ERROR: LoadError: MethodError: `convert` has no method matching convert(::Type{Tridiagonal{T}}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1})
This may have arisen from a call to the constructor Tridiagonal{T}(...),
since type constructors fall back to convert methods.
Closest candidates are:
  Tridiagonal{T}(::Array{T,1}, ::Array{T,1}, ::Array{T,1}, !Matched::Array{T,1})
  Tridiagonal{T}(::Array{T,1}, ::Array{T,1}, ::Array{T,1})
  Tridiagonal{Tl,Td,Tu}(::Array{Tl,1}, ::Array{Td,1}, ::Array{Tu,1})
  ...
 [inlined code] from bug.jl:9
 in anonymous at no file:7
 in include at .../julia/0.4.0/lib/julia/sys.dylib
 in include_from_node1 at .../julia/0.4.0/lib/julia/sys.dylib
 in process_options at .../julia/0.4.0/lib/julia/sys.dylib
 in _start at .../julia/0.4.0/lib/julia/sys.dylib
while loading bug.jl, in expression starting on line 1

Removing the if or for blocks results in this bug not triggering, so it looks like this has something to do with soft vs hard scope maybe. Rebinding an existing variable name is also required.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions