# Another world age problem

**URL:** https://discourse.julialang.org/t/another-world-age-problem/100029
**Category:** General Usage
**Tags:** world\_age
**Created:** [June 8, 2023, 12:45am UTC](https://discourse.julialang.org/t/another-world-age-problem/100029 "2023-06-08T00:45:23Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![user664303](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/user664303/32/37843_2.png) [@user664303](https://discourse.julialang.org/u/user664303)
#### Post date: [June 8, 2023, 12:45am UTC](https://discourse.julialang.org/t/another-world-age-problem/100029/1 "2023-06-08T00:45:23Z")

</div>

I’m suffering from a world age problem, that `Base.invokelatest` does not solve. A MWE demonstrating the problem is as follows:

```julia
module MyModule
export myfun
myfun(::Type{Int}) = 3

@generated function genfun(::Type{T}) where T
    return Base.invokelatest(myfun, T)
end
end

import .MyModule
MyModule.myfun(::Type{Float64}) = 4
MyModule.genfun(Float64)

```

This outputs:

> ERROR: MethodError: no method matching myfun(::Type{Float64})  
> The applicable method may be too new: running in world age 33480, while current world is 33481.  
> Closest candidates are:  
> myfun(::Type{Float64}) (method too new to be called from this world context.)  
> @ Main ~/.julia/dev/scratch.jl:11

Does anybody have any ideas as to if and how this can be fixed?

---

<div class="post-metadata">

### Author: ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)
#### Post date: [June 8, 2023, 12:59am UTC](https://discourse.julialang.org/t/another-world-age-problem/100029/2 "2023-06-08T00:59:51Z")

</div>

> [@user664303](#):
>
> ```julia
> myfun(::Int) = 3
> 
> ```

I think the problem is unrelated to world age. The quoted function defines `myfun` for an Int parameter, whereas you want to define it for a Type{Int} parameter.

---

<div class="post-metadata">

### Author: ![user664303](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/user664303/32/37843_2.png) [@user664303](https://discourse.julialang.org/u/user664303)
#### Post date: [June 8, 2023, 1:03am UTC](https://discourse.julialang.org/t/another-world-age-problem/100029/3 "2023-06-08T01:03:50Z")

</div>

Thanks for spotting the typo in my MWE. I’ve corrected this. You can see that it doesn’t fix the problem.

---

<div class="post-metadata">

### Author: ![user664303](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/user664303/32/37843_2.png) [@user664303](https://discourse.julialang.org/u/user664303)
#### Post date: [June 8, 2023, 1:15am UTC](https://discourse.julialang.org/t/another-world-age-problem/100029/4 "2023-06-08T01:15:39Z")

</div>

There is a helpful discussion on this particular problem [here](https://github.com/JuliaLang/julia/issues/23223).

---

<div class="post-metadata">

### Author: ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)
#### Post date: [June 8, 2023, 1:21am UTC](https://discourse.julialang.org/t/another-world-age-problem/100029/5 "2023-06-08T01:21:10Z")

</div>

Instead of:

> [@user664303](#):
>
> ```julia
> @generated function genfun(::Type{T}) where T
> return Base.invokelatest(myfun, T)
> end
> 
> ```

This works (Julia1.9 here):

```julia
@generated function genfun(t)
       return :(Base.invokelatest(myfun, t))
end

```

(as a general rule, generated functions should return a code expression… but there are bigger generated-function experts around)

---

<div class="post-metadata">

### Author: ![user664303](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/user664303/32/37843_2.png) [@user664303](https://discourse.julialang.org/u/user664303)
#### Post date: [June 8, 2023, 1:35am UTC](https://discourse.julialang.org/t/another-world-age-problem/100029/6 "2023-06-08T01:35:05Z")

</div>

Thanks. Yes, I’m aware of this solution. However, the point of generated functions is to do something at compile time. Your fix doesn’t - it is no better than using a normal function. What I’m trying to do is exploit some potential compile time optimizations. However, the world age problem makes it not possible.

---

<div class="post-metadata">

### Author: ![user664303](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/user664303/32/37843_2.png) [@user664303](https://discourse.julialang.org/u/user664303)
#### Post date: [June 8, 2023, 1:40am UTC](https://discourse.julialang.org/t/another-world-age-problem/100029/7 "2023-06-08T01:40:24Z")

</div>

[This PR sounds like a fix](https://github.com/JuliaLang/julia/pull/48611) has been merged into julia master branch. However, it looks like it’s not in v1.9.1, and I guess because it’s a change in behaviour, it won’t be released until v1.10. 🙁
