Disappearing methods from loaded libraries, seemingly iff `using PreallocationTools`

I have a weird issue that I am unable to reproduce in a MWE. It happens in the context of a reasonably large project.

Some methods are not available despite their libraries being loaded. For instance:

MethodError: no method matching dot(::Vector{Float64}, ::Vector{Float64})

Indeed, methods(dot) returns 0 methods, despite LinearAlgebra being loaded. The same happened recently, in the same project, with Base.collect.

From some experimentation, it seems to be the case that the issue occurs if and only if PreallocationTools (which is awesome!) is loaded. However, I was unable to reproduce that behaviour in a MWE.

Any pointers to what the issue could be would be much appreciated. Cheers.

I would need an MWE to see what’s going on there. PreallocationTools.jl is both small and does nothing particularly odd, you can read the whole source in like 15 minutes:

I would think PreallocationTools is a red herring here and it’s actually something completely different.

Fair enough. Thanks for the help!

I hit this too some time ago, but I wasn’t really sure either if it is me that messed things up or if it is a bug.

Just revisted my notes from back then and came up with this MWE:

module shadow

using LinearAlgebra

dot(x,y) = sum(x .* y) - 1

end # module shadow

Fire up a REPL and run

julia> methods(shadow.dot)
# 42 methods for generic function "dot":
...

Kill the REPL, comment the definition of dot and run again

julia> methods(shadow.dot)
# 1 method for generic function "dot":
...

So it seems to me that there is some silent shadowing going on with exported (and overridden) methods.

The above was tested on julia v1.8 but I have also seen it on julia v1.7 or even julia v1.6 (I believe it was).

EDIT: Might be related No error when method definition shadows local variable · Issue #15510 · JuliaLang/julia · GitHub

That’s what I would guess. But dot is neither imported, used, nor exported from PreallocationTools. It does not show up in the source at all. So something is shadowing it, but not PreallocationTools. Are you sure @joaovgranja you don’t have a dot(x,y) = ... overload somewhere and forgot to LinearAlgebra.dot(x,y)?

That was my first suspicion too, but no, I haven’t overloaded dot. And the same issue happens with Base.collect, which is also not overloaded. Still unable to track the issue down. Thanks for the MWE, @fatteneder!

parentmodule(dot) should point to the module.