Question regarding "WARNING: ignoring conflicting import"

No matter how many times I run the following, I get no warning or error:

using CSV: getrow

However, I get warning when I do this more than once:

module Test

function func()
    println("func")
end

end

using .Test: func

WARNING: ignoring conflicting import of Test.func into Main

Why do they behave differently?

This is something that is easy to stumble upon. I am not an expert but I would say to a good degree the first case can be understood in the following way:
You tell Julia to bring a function getrow from the module CSV into scope. Julia will first check if this module in your environment, and then import the function from the currently installed version of the module.
If you do that again, the module (and thus also the function) will be inherently the same, so everything should be fine.

In the second case you are first defining a new module with the name Test and again bringing the function definition into global scope. So far so good.

However now you do the same thing again: You re-define the module and therefore there is an inherent conflict which method is the correct one, the one from the previously defined module or the current one.

(I have assumed that you also defined the module again. I have no way of checking this right now, but I believe just calling using .Test: func several times should not throw a warning, right?)

Overall, I am not sure what the reason is why modules do not simply get overwritten in the same way that functions are. For this, the Revise-based workflow is best used: I often develop my module, say in some folder Test/src/Test.jl and then simply type ]dev Test to add this module to the environment. Revise picks up all changes I make to the file so whenever I safe the file, the functions get updated.
I think you can also put your module in a single file and explicitly call using Revise; includet("fileWithModule.jl") which should also do the trick as far as I know.
Hope that helps!

1 Like
julia> module F
       f() = 1
       end
Main.F

julia> using .F: f

julia> using .F: f

julia> f()
1

julia> module F
       f() = 2
       end
WARNING: replacing module F.
Main.F

julia> f()
1

julia> using .F: f
WARNING: ignoring conflicting import of F.f into Main

julia> f()
1

julia> F.f()
2

2 Likes

Now I understand what happened. Thank you so much for the useful tips too!

2 Likes