Error with modules sharing types

Pasting exactly the code you provided into the REPL works as expected:

julia> # M1.jl
       module M1
           export M1Type
           struct M1Type
               data::Real
           end
       end
Main.M1

julia> # M2.jl
       module M2
           using ..M1
           export f
           function f(x::M1Type)
               
           end
       end
Main.M2

julia> # At the REPL (or main module)
       using .M1

julia> using .M2

julia> f(M1Type(1))

julia> 

so the problem has something to do with how you are actually including your files. The results you’re seeing are consistent with having called include() on the same file in multiple different modules, which you not ever do (see Organizing modules. Is it OK to organize a project using several modules in Julia? - #5 by rdeits , Organizing structs and modules - #3 by rdeits , etc). Can you be more explicit about how you’ve actually set up your code to run into the problem you’re seeing?

2 Likes