The applicable method may be too new: running in world age 32331, while current world is 32332

I want to change the field types of R to be of StaticArray. However, I am having the below error. Could you please help me to solve this issue?

using LinearAlgebra, StaticArrays
Base.@kwdef mutable struct Rs
  I::Vector{Float64} = [1,2,3]
  Dot::Array{Float64, 2} = [1 1 1; 2 2 2; 3 3 3]
end

Base.@kwdef mutable struct S_Rs
  I::MVector{3,Float64}
  Dot::MMatrix{3,3,Float64,9}
end

function all()
  R = Rs[];
  push!(R, Rs());
  push!(R, Rs());

    @eval Main.S_Rs(a::Main.Rs) = Main.S_Rs($([:(a.$x) for x in fieldnames(Main.Rs)]...))
    R = Main.S_Rs.(R);
end

R = all();
ERROR: MethodError: no method matching S_Rs(::Rs)
The applicable method may be too new: running in world age 32331, while current world is 32332.

Put that @eval line at the top level outside the all() function.

1 Like

Thank you very much. Yes, it works. There is a small issue that when I run it, it always print R in the REPL (as below) although I have ; at the end of each line. I do not know why and is there a way to stop printing it?

2-element Vector{S_Rs}:
 S_Rs([1.0, 2.0, 3.0], [1.0 1.0 1.0; 2.0 2.0 2.0; 3.0 3.0 3.0])
 S_Rs([1.0, 2.0, 3.0], [1.0 1.0 1.0; 2.0 2.0 2.0; 3.0 3.0 3.0])

I’m guessing you’re doing include("file.jl") at the REPL? Semicolons aren’t needed to avoid printing the output of each line. Rather, it’s only things you write at the REPL that will show their result unless there’s a final ;. Having semicolons inside that file.jl will have no effect; but if you don’t want to see the result of the final expression when including it, you put the semicolon after the include("file.jl"); at the REPL.

2 Likes

The above code is in script.jl and I open it by vs code, then click “Execute active file in REPL”.

Just add one line containing nothing at the end of the included file, so that the value returned to the REPL is nothing (which is not displayed by the REPL) ?

1 Like

As a last resort, you can use Base.invokelatest.

1 Like

Where should I put the nothing given that the above code is in script.jl and I open it by vs code, then click “Execute active file in REPL”.

Thanks for your suggestion, but actually I did not know where to put Base.invokelatest. in my code?

Put it as the last line of script.jl then?

1 Like
julia> function all()
         R = Rs[];
         push!(R, Rs());
         push!(R, Rs());

           @eval Main.S_Rs(a::Main.Rs) = Main.S_Rs($([:(a.$x) for x in fieldnames(Main.Rs)]...))
           f(R) = Base.invokelatest(Main.S_Rs, R)
           R = f.(R);
       end
all (generic function with 1 method)

julia> all()
2-element Vector{S_Rs}:
 S_Rs([1.0, 2.0, 3.0], [1.0 1.0 1.0; 2.0 2.0 2.0; 3.0 3.0 3.0])
 S_Rs([1.0, 2.0, 3.0], [1.0 1.0 1.0; 2.0 2.0 2.0; 3.0 3.0 3.0])
1 Like

Thank you all!