Cross-referencing a function from a submodule defined later

I want to cross ref a function defined in a later submodule. Here is an example:

module A

"""
[`foo`](@ref)
"""
module B
end

module C
""" foo """
function foo end
end
end

This SO answer suggests that foo should be imported in the B submodule, however one cannot import C in B since it’s defined later (and in my more complex usecase it’s not possible to change the order.
So

module B
using ..C: foo
end

naturally does not work

Fully qualifying the binding as A.C.foo should work:

module A

"""
[`foo`](@ref A.C.foo)
"""
module B
# need to import A to get around the problem of C not being defined
using ..A

"""
[`foo`](@ref A.C.foo)
"""
function bar end

end


module C
""" foo """
function foo end
end
end
2 Likes