# Method definition overwritten warnings when compiling cache or "using module" twice

I have some code with this general structure

``````push!(LOAD_PATH, Base.source_dir())

Base.compilecache(Base.PkgId("Mod1"))

using Mod1
using Mod2

Mod2.bar(5)
``````

where Mod2.jl also has

``````using Mod1
``````

When I do this, I get a large number of “WARNING: Method definition __ overwritten…” for methods that are indeed in Mod1.

First, I get these warnings from the compilecache call (which is not there to be useful so much as to figure out what’s going on). Then I get them again for the “using Mod1” in Mod2.

I don’t get warnings for all the methods in Mod1 though, probably only about 1-2% of them, actually. I can’t see anything that is special about those methods.

I’d give a complete replicable example, but I haven’t been able to create one. My Mod1 is huge, with more than 10,000 lines of code. For simple Mod1 equivalents, I don’t get any warnings (which is consistent with how I only get warnings for a small portion of the functions).

If I put precompile(false) in Mod1, the warnings go away. (Similarly, they might go away if I used include instead of using to bring in the modules.) But I’d like to (a) be able to precompile and (b) understand this so I have a good workflow in Julia in the future.

Help? Thanks.

1 Like

Not sure if you still need this, but I’ve just went through something similar.

For one of my source files, let’s say file.jl, I was getting warnings for all the types and functions defined.
The weird thing was that they said something like method (…) at file.jl:5 is overwritten at file.jl:5.

my module_name.jl looked something like:

``````module module_name
include("file1.jl")
include("file2.jl")
end
``````

and the problem was that I had include(“file1.jl”) in file2.jl and that include was overwriting the methods.