Help with solving a world age error in package on julia master

My package https://github.com/KristofferC/OhMyREPL.jl started failing on master with the error.

julia> WARNING: Caught an exception in the keymap:
ERROR: MethodError: no method matching (::OhMyREPL.Prompt.##1#28)(::Base.LineEdit.MIState, ::Base.REPL.LineEditREPL, ::String)
The applicable method may be too new: running in world age 20392, while current world is 20418.
Closest candidates are:
  #1(::Any, ::Any, ::Any) at /home/kristoffer/.julia/v0.6/OhMyREPL/src/repl.jl:72 (method too new to be called from this world context.)

The error occurs as soon as the package is loaded and a key is pressed.
What the function is supposed to do is to change some hotkeys the REPL normally use to call a few other functions. IIUC this error happens when a method defined in a running context is tried to be called in that context? The method that is said to be too new (at OhMyREPL/src/repl.jl:72) is an anonymous function that gets bound to a key,

    D["*"]    = (s, data, c) ->  (LineEdit.edit_insert(s, c); rewrite_with_ANSI(s))

How should I rewrite this function as to not run into the current problems?

I made a minimum working example that exhibits the problem:

module REPLInserter

import Base.LineEdit

say_hello() = println("Hello")

function create_keybindings()
	D = Dict{Any, Any}()
    D["*"]    = (s, data, c) ->  (LineEdit.edit_insert(s, c); say_hello())
    return D
end
const KEYBINDS = create_keybindings()


function insert_keybindings()
    repl = Base.active_repl
    mirepl = isdefined(repl,:mi) ? repl.mi : repl
    main_mode = mirepl.interface.modes[1]
    main_mode.keymap_dict = LineEdit.keymap([KEYBINDS, main_mode.keymap_dict])
end

end

REPLInserter.insert_keybindings()

Run this, then press a button in the REPL.

I have no idea what the solution is, but it started happening on the 0.6 Travis for me as well, though with the eval function:

The REPL issue is a base REPL bug. the CxxWrap one is most likely a package bug.

Also Cuba.jl and Cubature.jl are currently failing on Julia master:

Any hint about how to fix this?

More info about my crash here: World age error when using eval · Issue #19754 · JuliaLang/julia · GitHub

But it seems more appropriate to discuss here, then. I have no idea what the error even means, let alone what I might be doing wrong to provoke it.

The error means that you are calling a method that’s too new. See here for the doc. The error message shows you that it’s the module specific eval that’s too new and since these are automatically defined when the module is created it’s likely caused by creating modules dynamically and trying to call methods (eval) defined in it. This seems to be what you are doing.

The easiest workaround is to use eval(mod, expr) instead of mod.eval(expr). Also note that instead of using try-catch and eval of a single simple with a no-op interpolation you can just do

if isdefined(parent_module, mod_sym)
    jl_mod = getfield(parent_module, mod_sym)
else
    jl_mod = Core.eval(parent_module, :(module $mod_sym end))
end

No need for jl_mod = nothing either.

I’m reading that section of the manual right now, I hope to understand how to adapt the package.

However there is no eval nor try-catch in Cuba.jl, I’m not sure what you’re referring to.

That was the reply to @barche It’s harder to see the issue from the log for Cuba.jl Is it using generated functions?

No. A possible pitfall may be generic_integrand! function:
https://github.com/giordano/Cuba.jl/blob/6802933fc82c4edc1ec6a93159bedda17f483a57/src/Cuba.jl#L95
A pointer to this function is defined at init time.

I wouldn’t say there is any function redefinition in Cuba.jl (and Cubature.jl is pretty similar), the manual didn’t help me much.

Thanks a lot, working fine now! An additional complication was that the eval at the reported line wasn’t actually the problem, it was later use of eval (in the new module) that triggered it. Replacing all other occurrences with Core.eval fixed it though.

It would be good to have a better solution for callback functions than calling eval. https://github.com/JuliaLang/julia/issues/19774