Julia by default imports many names into scope. Is there a way to get a warning when I inadvertently overwrite one of them?
In the context of modules and Base functions, Julia already does warn you if you overwrite a name. See the below examples that work on v0.4.5
:
MODULES:
In modA.jl:
module modA
export test
function test()
println("modA")
end
end
In modB.jl:
module modB
export test
function test()
println("modB")
end
end
In REPL:
julia> using modA
julia> using modB
WARNING: Using modB.test in module Main conflicts with an existing identifier
julia> test()
"modA"
BASE FUNCTIONS:
In REPL:
julia> function +(x::Float64, y::Float64)
println("my addition")
end
julia> WARNING: module Main should explicitly import + from Base
WARNING: Method definition +(Float64, Float64) in module Base at float.jl:208
overwritten in module Main at none:2.
As far as I am aware, this does not work with user defined functions; see below:
julia> function test(x::Float64, y::Float64)
println("First Definition")
end
julia> test(1.0, 2.0)
First Definition
julia> function test(x::Float64, y::Float64)
println("Second Definition")
end
julia> test(1.0, 2.0)
Second Definition
Did you have a different context in mind for imported names?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With