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

**URL:** <https://discourse.julialang.org/t/help-with-solving-a-world-age-error-in-package-on-julia-master/1126>\
**Category:** General Usage\
**Created:** [December 24, 2016, 12:17am UTC](https://discourse.julialang.org/t/help-with-solving-a-world-age-error-in-package-on-julia-master/1126 "2016-12-24T00:17:26Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 24, 2016, 12:17am UTC](https://discourse.julialang.org/t/help-with-solving-a-world-age-error-in-package-on-julia-master/1126/1 "2016-12-24T00:17:26Z")

</div>

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

```nohighlight
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,

```nohighlight
    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?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 24, 2016, 10:03am UTC](https://discourse.julialang.org/t/help-with-solving-a-world-age-error-in-package-on-julia-master/1126/2 "2016-12-24T10:03:32Z")

</div>

I made a minimum working example that exhibits the problem:

```julia
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.

---

<div class="post-metadata">

**Author:** ![barche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barche/32/79_2.png) [@barche](https://discourse.julialang.org/u/barche)\
**Post date:** [December 25, 2016, 3:40pm UTC](https://discourse.julialang.org/t/help-with-solving-a-world-age-error-in-package-on-julia-master/1126/3 "2016-12-25T15:40:52Z")

</div>

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:

> **[Travis CI - Test and Deploy with Confidence](https://app.travis-ci.com/JuliaInterop/CxxWrap.jl/jobs/186630015)**
>
> Travis CI enables your team to test and ship your apps with confidence. Easily sync your projects with Travis CI and you'll be testing your code in minutes.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [December 25, 2016, 9:05pm UTC](https://discourse.julialang.org/t/help-with-solving-a-world-age-error-in-package-on-julia-master/1126/4 "2016-12-25T21:05:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [December 29, 2016, 3:34pm UTC](https://discourse.julialang.org/t/help-with-solving-a-world-age-error-in-package-on-julia-master/1126/5 "2016-12-29T15:34:18Z")

</div>

Also [Cuba.jl](https://github.com/giordano/Cuba.jl) and [Cubature.jl](https://github.com/stevengj/Cubature.jl) are currently failing on Julia master:

- [http://pkg.julialang.org/logs/Cuba\_0.6.log](http://pkg.julialang.org/logs/Cuba_0.6.log)
- [http://pkg.julialang.org/logs/Cubature\_0.6.log](http://pkg.julialang.org/logs/Cubature_0.6.log)

Any hint about how to fix this?

---

<div class="post-metadata">

**Author:** ![barche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barche/32/79_2.png) [@barche](https://discourse.julialang.org/u/barche)\
**Post date:** [December 29, 2016, 3:44pm UTC](https://discourse.julialang.org/t/help-with-solving-a-world-age-error-in-package-on-julia-master/1126/6 "2016-12-29T15:44:39Z")

</div>

More info about my crash here: [World age error when using eval · Issue #19754 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/19754#issuecomment-269646295)

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.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [December 29, 2016, 3:50pm UTC](https://discourse.julialang.org/t/help-with-solving-a-world-age-error-in-package-on-julia-master/1126/7 "2016-12-29T15:50:28Z")

</div>

The error means that you are calling a method that’s too new. See [here](http://docs.julialang.org/en/latest/manual/methods.html#Redefining-Methods-1) 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

```julia
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.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [December 29, 2016, 3:56pm UTC](https://discourse.julialang.org/t/help-with-solving-a-world-age-error-in-package-on-julia-master/1126/8 "2016-12-29T15:56:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [December 29, 2016, 4:38pm UTC](https://discourse.julialang.org/t/help-with-solving-a-world-age-error-in-package-on-julia-master/1126/9 "2016-12-29T16:38:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [December 29, 2016, 4:49pm UTC](https://discourse.julialang.org/t/help-with-solving-a-world-age-error-in-package-on-julia-master/1126/10 "2016-12-29T16:49:47Z")

</div>

No. A possible pitfall may be `generic_integrand!` function:  
[https://github.com/giordano/Cuba.jl/blob/6802933fc82c4edc1ec6a93159bedda17f483a57/src/Cuba.jl#L95](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 _re_definition in `Cuba.jl` (and `Cubature.jl` is pretty similar), the manual didn’t help me much.

---

<div class="post-metadata">

**Author:** ![barche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barche/32/79_2.png) [@barche](https://discourse.julialang.org/u/barche)\
**Post date:** [December 29, 2016, 7:07pm UTC](https://discourse.julialang.org/t/help-with-solving-a-world-age-error-in-package-on-julia-master/1126/11 "2016-12-29T19:07:26Z")

</div>

> [@yuyichao](#):
>
> it’s likely caused by creating modules dynamically and trying to call methods (eval) defined in it

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.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 30, 2016, 1:50pm UTC](https://discourse.julialang.org/t/help-with-solving-a-world-age-error-in-package-on-julia-master/1126/12 "2016-12-30T13:50:41Z")

</div>

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