I’ve spent quite a bit of time hunting down a bug that was caused by redefining a Base type. E.g.:
Int = find(something) # I am finding interior nodes in a grid
# a function defined somewhere else in the notebook
function do_something()
A = Int[]
push!(A, 5)
end
do_somthing()
# ERROR: MethodError: no method matching push!(::Int64, ::Int64)
It took me a while to find this. Obviously I should have chosen better naming. But in a notebook neither syntax highlighting warned me, nor an actual Julia warning.
What surprised me is
const T = Int64; T = 5 throws an error
Int = 3 or Float64 = sqrt is ok.
Should these "standard types" for lack of a better name be `const`?
julia> eval(Core, :(Int = 5))
ERROR: invalid redefinition of constant Int
Stacktrace:
[1] eval(::Module, ::Any) at ./boot.jl:235
If you use Int before you assign to it, at least you get a warning:
julia> Int
Int64
julia> Int = 5
WARNING: imported binding for Int overwritten in module Main
5
If you could not assign to a type (or something else) exported from Base, every new export from Base would potentially be breaking, so that’s not really an option.
julia> using Lint
julia> lintstr("Int = 4")
1-element Array{Lint.LintMessage,1}:
none:1 I392 Int: local variable might cause confusion with a synonymous export from Base