import Base.+ should work (if you do it in the module before your function definition). However, if you want to qualify the function name itself, you have to quote it with : as Base.:+.
It seems a little inconsistent, so I filed a PR to fix both the error message and to allow quoting in import statements:
JuliaLang:master ← JuliaLang:sgj/methoderror.op
opened 04:18PM - 04 Sep 19 UTC
TLDR: This PR allows quoting in `import` statements, e.g. `import Base.:+`, simi… lar to other Julia contexts, and uses quoting for `MethodError` warnings about shadowed operators.
As was [noted recently on discourse](https://discourse.julialang.org/t/definition-of-unary-operator-inside-a-module-removes-the-base-definition/28371), the `MethodError` printing currently shows a potentially confusing suggestion when a function shadows a `Base` function if it is an operator, and in general the quoting of symbols (e.g. `Base.+` vs. `Base.:+`) was a bit inconsistent.
For example, if you accidentally shadow `+`, it prints `You may have intended to import Base.+`, which may be confusing because if you try to define the function as `Base.+` Julia will give an error. This PR changes the error message to quote operators.
Unfortunately, while `function Base.:+(...)` works, `import Base.:+` gave a syntax error, which seems a little inconsistent. So this PR also updates the parser to allow quoted symbols in `import` statements. Backwards compatible since it was a syntax error previously.
4 Likes