# Avoid error message for function name conflict

**URL:** <https://discourse.julialang.org/t/avoid-error-message-for-function-name-conflict/37176>\
**Category:** General Usage\
**Created:** [April 7, 2020, 2:39pm UTC](https://discourse.julialang.org/t/avoid-error-message-for-function-name-conflict/37176 "2020-04-07T14:39:04Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Post date:** [April 7, 2020, 2:39pm UTC](https://discourse.julialang.org/t/avoid-error-message-for-function-name-conflict/37176/1 "2020-04-07T14:39:04Z")

</div>

Hi,

Is there a convenient way to avoid the error message when `using` two modules which export a function the same name?

Scenario is that package A depends on B and C. C just added a function which collides with one in B. Both C and B export alot of things which are used in A.

Is there an easier way than manually importing/qualifying everything out of B and/or C which A makes use of? Something like “use all but this from B”.

---

<div class="post-metadata">

**Author:** ![jlperla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlperla/32/34332_2.png) [@jlperla](https://discourse.julialang.org/u/jlperla)\
**Post date:** [April 7, 2020, 2:50pm UTC](https://discourse.julialang.org/t/avoid-error-message-for-function-name-conflict/37176/2 "2020-04-07T14:50:45Z")

</div>

Out of curiosity: what were the function names and where the functions take at least one argument which was defined in the package? Were the functions conceptually very close in what they expected and returned, or so fundamentally different you would never mix them up?

---

<div class="post-metadata">

**Author:** ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Post date:** [April 7, 2020, 3:12pm UTC](https://discourse.julialang.org/t/avoid-error-message-for-function-name-conflict/37176/3 "2020-04-07T15:12:15Z")

</div>

To satisfy your curiosity then 🙂 : Name is flatten and in one package it turns an ND array into a matrix and in the other it turns a graph into an array of its vertices.

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [April 7, 2020, 7:04pm UTC](https://discourse.julialang.org/t/avoid-error-message-for-function-name-conflict/37176/4 "2020-04-07T19:04:52Z")

</div>

This is probably helpful:

> [@Function name conflict: ADL / function merging?](https://discourse.julialang.org/t/function-name-conflict-adl-function-merging/10335/24):
>
> Another option for this particular case: module A export foo, AA struct AA end foo(::AA) = :A end module B export foo, BB struct BB end foo(::BB) = :B end module C import A, B import A: AA import B: BB foo(x::AA) = A.foo(x) foo(x::BB) = B.foo(x) @show foo(AA()) @show foo(BB()) end i.e., just define your own function. You could probably automate this process using a macro and some introspection. But I agree with others that having functions from different packages be automatically ‘merged’ w…

It appears that either fully qualified names (as in `A.flatten`) or explit importing of all used objects are the only options.

However, one entry suggests to redefine the conflicting names to make the code “nicer” as in `myflatten(x) = A.flatten(x)`. That looks workable to me.

---

<div class="post-metadata">

**Author:** ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Post date:** [April 7, 2020, 7:34pm UTC](https://discourse.julialang.org/t/avoid-error-message-for-function-name-conflict/37176/5 "2020-04-07T19:34:23Z")

</div>

Thanks,

Using fully qualified names in A works of course, but it does not remove the warning when using/importing A.

To make matters worse, A [reexports](https://github.com/simonster/Reexport.jl) both B and C ☹ .

Oh well, I guess I just learned a valuable lesson about encapsulation and it does not cost anything more than a major revision number and the inconvenience of having to always import stuff from B and C when using A 🙂

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [April 8, 2020, 2:46pm UTC](https://discourse.julialang.org/t/avoid-error-message-for-function-name-conflict/37176/6 "2020-04-08T14:46:48Z")

</div>

About that `using` warning … I probably misunderstand, but this does not produce a warning:

```julia
# test1.jl
module B
    export foo
    foo() = println("B");
end

module C
    export foo
    foo() = println("C");
end

module A
    using ..B, ..C
    B.foo()
    C.foo()
end

using .A

```

and then on the REPL

```julia
julia> include("../scratch/test1.jl")
B
C

```

Sorry if I misunderstand the kind of warning you are talking about.

---

<div class="post-metadata">

**Author:** ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Post date:** [April 8, 2020, 6:18pm UTC](https://discourse.julialang.org/t/avoid-error-message-for-function-name-conflict/37176/7 "2020-04-08T18:18:41Z")

</div>

@hendri54

Thanks alot for this!

It seems like the warning (which indeed is very helpful and potentially sanity preseving) is only produced when an actual unqualified call to the function is done in the module:

```julia
module B
   export foo
   foo() = println("B");
end

module C
   export foo
   foo() = println("C");
end

module A
   using ..B, ..C
   B.foo()
   C.foo()
   foo()
end

using .A

```

REPL:

```julia
julia> include("footest.jl")
B
C
WARNING: both C and B export "foo"; uses of it in module A must be qualified
ERROR: LoadError: UndefVarError: foo not defined

```

I could have sworn I had qualified all usage of flatten in A and I still got the warning when using it. I will double check it again but I think you just saved me one internet bit for a major revision number 🙂

---

<div class="post-metadata">

**Author:** ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Post date:** [April 8, 2020, 8:11pm UTC](https://discourse.julialang.org/t/avoid-error-message-for-function-name-conflict/37176/8 "2020-04-08T20:11:08Z")

</div>

Ok, I have narrowed it down to this (it didn’t take me 2 hours, I was watching TV with the wife until she got tired, I promise):

```julia
#footest.jl
module B
    export foo
    foo() = println("B");
end

module C
    export foo
    foo() = println("C");
end

module A
    using Reexport
    @reexport using ..B
    @reexport using ..C
    import InteractiveUtils: subtypes
    subtypes(Integer)

    B.foo()
    C.foo()
end

using .A

```

```julia
julia> include("footest.jl")
WARNING: both C and B export "foo"; uses of it in module A must be qualified
B
C

```

Next stop is to see if there is some kind of witchcraft going on in Reexport could explain this…

---

<div class="post-metadata">

**Author:** ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Post date:** [April 8, 2020, 8:32pm UTC](https://discourse.julialang.org/t/avoid-error-message-for-function-name-conflict/37176/9 "2020-04-08T20:32:19Z")

</div>

This is the workaround I managed to come up with:

```julia
module B
    export foo
    foo() = println("B");
end

module C
    export foo
    foo() = println("C");
end

module A
    using Reexport
    @reexport using ..B
    @reexport using ..C

    module AA
        export T, TT
        abstract type T end
        struct TT <: T end
    end

    @reexport using .AA

    import InteractiveUtils: subtypes
    subtypes(AA, T)
end

using .A

```

Types `TT` and `T` where originally defined inside `A`, but that caused `subtypes` to trigger the warning when called. Putting them inside an internal module which is reexported seemed to avoid the issue.

Reexport was innocent here. Replacing it with explict `export`s (without the workaround) produced the same behaviour.

---

<div class="post-metadata">

**Author:** ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Post date:** [April 8, 2020, 8:57pm UTC](https://discourse.julialang.org/t/avoid-error-message-for-function-name-conflict/37176/10 "2020-04-08T20:57:27Z")

</div>

Less intrusive workaround:

```julia
module B
    export foo
    foo() = println("B");
end

module C
    export foo
    foo() = println("C");
end

module A
    using Reexport
    using ..B
    using ..C

    abstract type T end
    struct TT <: T end
    import InteractiveUtils: subtypes
    @show subtypes(A, T)

    @reexport using ..B
    @reexport using ..C
end

using .A

```
