Trying not to overload Base.open

I am trying to define a method open in my own module. I have no interest in overloading Base.open and it’s not imported in my module.
However, Travis now complains with:

ERROR: LoadError: error in method definition: function Base.open must be explicitly imported to be extended

I have never seen this issue before, and I have just updated some dependencies, not my Julia code.
The code in question is this:


I am baffled. Can I not innocently define a function named open in my own module? I am neither importing Base.open, nor am I exporting my own LCIO.open.
If anybody could help shed light on what’s causing this error message, that would be greatly appreciated.

I’m not familiar with how your package is built, but simply defining open does not mean Base.open is imported. It seems you are using Base.open in an included file though, is it possible that the deps/deps.jl file uses the definition from Base (e.g., open(<file>, <mode>))?

$ cat tmp.jl
module tmp

f = "hello"
# uncomment the next line to break things
# include("dep.jl")

function open()
    global f
    println(f)
end

end
$ cat dep.jl
f = open("test.txt", "r") do f
        readline(f)
    end
$ cat test.txt
This is a testline.

Including tmp.jl as it is above will work and you can call tmp.open(). Additionally uncommenting the include for dep.jl will error with the importing message. The solution is to define your open as LCIO.open.

The error message is informing you of a name clash. They can be resolved by clearly stating who owns the new method.

1 Like

Thanks for your help.
You are right, the culprit was in an included file.
The tricky part was that this method had been defined on the C++ side, and somehow the way that names are exported must have changed in CxxWrap. The relevant discussion happens here:

An open method does not have to be exported from Cxx for this to happen. Using the default open from Base in an included file is enough since Base is of course exporting open, see the example I provided. Further, the name clash does not happen with Cxx but with Base.

Sure. In this case, however, there’s only one included file, deps.jl, which does not include Base.open or define any other method called open.