Skip to content

Using include inside __init__ causes using to not work right #26788

Closed

Description

for Julia 0.6
Easier to explain with examples.
But basically if you put an include inside an __init__,
then it does not have access to names that were added to the calling namespace by using.

But if you put a using at the top of the included file, then all is good.
(But that I feel should be an error).

Works

all in one file: main.jl

module Foo 
    export fooit
    fooit()=println("IT was fooed")
end

module Bar
    using Foo
    __init__() = fooit()

end

using Bar

running that outputs "IT was fooed"

Doesn't work

Running main.jl gives
** InitError: LoadError: mUndefVarError: fooit not defined
while loading .../initstuff.jl **

in initstuff.jl:

fooit()

in main.jl:

module Foo
    export fooit
    fooit()=println("IT was fooed")
end


module Bar
    using Foo
    function __init__()
        include("initstuff.jl")
    end

end

using Bar

Works (but maybe shouldn't?)

I feel like this should be an error, as directly substituting the contents of initstuff.jl into __init__ would be an error.

in initstuff.jl:

using Foo
fooit()

in main.jl:

module Foo
    export fooit
    fooit()=println("IT was fooed")
end


module Bar
    using Foo
    function __init__()
        include("initstuff.jl")
    end

end

using Bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions