Inconsistent Base method overwrite behaviour

This doesn’t look right to me – looks like methods in Base are not automatically loaded until something triggers that, leading to inconsistent behaviour.

   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.0.0 (2018-08-08)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> function fetch(u)
       # code
       end
fetch (generic function with 1 method)

And in a new session:

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.0.0 (2018-08-08)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> fetch
fetch (generic function with 5 methods)

julia> function fetch(u)
              # code
              end
ERROR: error in method definition: function Base.fetch must be explicitly imported to be extended
Stacktrace:
 [1] top-level scope at none:0

This is by design, so you can use Base-names (or other “used” modules) in your code. However, once a name has been resolved to an imported binding, you cannot go back, as your second example shows.

2 Likes

One rather unfortunate thing is that autocompletions trigger name resolution:

λ j1 --quiet
julia> seek<\tab>
seek      seekend    seekstart
julia> seek = 2
ERROR: cannot assign variable Base.seek from module Main
Stacktrace:
 [1] top-level scope at none:0

julia> seekend = 3
ERROR: cannot assign variable Base.seekend from module Main
Stacktrace:
 [1] top-level scope at none:0
2 Likes

Yes, exactly, that what was bothering me :slight_smile:

Sounds issue-worthy to me.

The auto completion issue should be fixed by
https://github.com/JuliaLang/julia/pull/29962