julia

Julia LoadError: Creating a new global in closed module `__toplevel__` breaks incremental compilation because the side effects will not be permanent


I have written some code in Julia aka Julialang.

When I try to run this code, I get the following error:

LoadError: Creating a new global in closed module `__toplevel__` (FUNCTION_NAME) breaks incremental compilation because the side effects will not be permanent

What does this error mean and what causes it?

I reduced the code I had in one of my modules down to this:

module ExampleModule

export exampleFunction1
export exampleFunction2

function exampleFunction1()
    # blaa blaa
end

end # <-- Note: See answer below

function exampleFunction2()
    # blaa blaa
end

end

Solution

  • This error can be caused by defining a function outside of a module.

    In this particular case, this was the cause of the error in my code, however I believe there can be other causes too. (Judging by search results online, all of which are unrelated to this context.)

    In the example code provided above, there is an extra end keyword, which is marked by the comment.

    It is relatively easy to introduce an additional end by accident.

    In this case, the extra end causes the module definition to complete, and then the final function is defined outside of the module.