Accidental overwrite base function name

Not sure if it’s a bug or expected behavior: people may not know all the names of the built-in functions, and on a fresh start, the built-in function may be overwritten: on a fresh start, things like

diff = 0

would run without warning, and the function diff() will be over-written. On the other hand, if the function diff() has already been used, or one has used the help ?diff then the assignment diff = 0 would error; guess it’s fine if the function is overwritten if it’s never used, and if another module uses such function it’s also not affected:

module test
       function g(x)
              diff(x)*im
       end
end

@code_lowered test.g(rand(3))

shows

CodeInfo(
1 ─ %1 = Main.test.diff(x)
│   %2 = %1 * Main.test.im
└──      return %2
)

Should julia always print error message when over-writing functions in stdlib regardless of whether it’s been used or is the current behavior fine as is? Thanks!

2 Likes

The current behavior is intended. Otherwise adding new names to base would be hugely breaking.

6 Likes

makes sense, thanks!