Reexport.@reexport from submodule does not work: how to diagnose?

I have been using Reexport.@reexport in many of my packages and have never had an issue. At the moment, however, it is not working in one package, even though I think it is used in the same way as in my other packages.

The structure of the problematic package looks basically like this:

module MyModule

export MyType

struct MyType
end

module MySubModule
    using Reexport
    @reexport using ..MyModule

    export MyType2

    struct MyType2
    end

end  # MySubModule

end  # MyModule

The goal here is to make all the exported symbols of the enclosing MyModule become available when the submodule MySubModule is used. When this works (like my other packages), I am able to do this:

julia> using MyModule.MySubModule

julia> MyType()  # defined in MyModule, but still exported

However, at the moment I get

julia> MyType()
ERROR: UndefVarError: `MyType` not defined
[...]

Strangely, I can see that MyType is available:

julia> names(MyModule)
2-element Vector{Symbol}:
 :MyModule
 :MyType

Also, qualifying MyType with the module name works:

julia> MyModule.MyType()
MyModule.MyType()

In fact, If I define MyModule as shown above, it works as intended, but the particular package I am developing is experiencing the issue described here, even though I think its structure is the same as MyModule. Maybe I have made some trivial mistakes, but I cannot identify it.

Are there ways to understand what is causing this issue?

Which Julia version? Perhaps this is breaking change in `names` · Issue #54885 · JuliaLang/julia · GitHub if you are using the master branch.

Sorry, forgot to put the version number. I am not using master:

julia> VERSION
v"1.10.4"

I realized why. My package was actually like

module MyModule

module MySubModule
    using Reexport
    @reexport using ..MyModule

    export MyType2

    struct MyType2
    end

export MyType  # export after defining MySubModule

struct MyType
end

end  # MySubModule

end  # MyModule

The difference from the code shown previously is that MyType is exported and defined after MySubModule is defined. So, at the point where MySubModule was defined, MyType was yet to be exported. This made @reexport using ..MyModule in MySubModule unaware that MyType was exported from MyModule.

Exporting MyType before defining MySubModule removed the error. Here is the working code:

module MyModule

export MyType  # export before defining MySubModule

module MySubModule
    using Reexport
    @reexport using ..MyModule

    export MyType2

    struct MyType2
    end

struct MyType
end

end  # MySubModule

end  # MyModule

The reason I was exporting MyType after defining MySubModule was because I use the coding style of exporting symbols in the file where they are defined. My actual code was organized into several files such that

module MyModule

include("mysubmodule.jl")  # define MySubModule
include("mytype.jl")  # define and export MyType

end  # MyModule

In the actual code, mysubmodule.jl contained types used as the parameters of MyType, so I had to include mytype.jl after mysubmodule.jl. This made MyType exported after defining MySubModule, because MyType was exported in mytype.jl.

I know some people export all the symbols in <package name>.jl file, such that the contents of the file looks like

module MyModule

export MyType  # exported here, even though defined in mytype.jl

include("mysubmodule.jl")  # define MySubModule
include("mytype.jl")  # define but not export MyType

end  # MyModule

I thought exporting symbols in the file where they are defined looks more modular, but maybe I should consider changing my coding style because it has the pitfall explained above…