MethodError Mystery: Unexpected Third Argument in Constructor Call After Julia Kernel Upgrade (1.5 to 1.9)

Sorry in advance if this question is stupid and belongs in the ‘new to julia’ subforum. From what I could gather that one is focused more on installing julia, so I put it here instead.

Hey!
I am trying to get some code to run on a newer julia kernel version (jump from 1.5 to 1.9) including newer package versions so I have to debug a lot of function arguments.

I am hardstuck on a very specific one:

When calling

A = constructor(b, c)

running the code fails with the following method error:

MethodError: no method matching Constructor(::b,::c,::d).

Closest candidates are:
    Constructor(::b,::c)

When printing typeof(b) and typeof(c) before the constructor call, it is showing the correct type.

Why is there suddenly a third argument showing up in the MethodError? How can I call the constructor without this mysterious third argument?

In case this is a problem with the specific package containing the constructor in question, here is my code:

println(SimpleGraph(0))
println(typeof(SimpleGraph(0)))
println(typeof([]))
new_graph = EmbeddedGraph(SimpleGraph(0),[])

and the output:

SimpleGraph{Int64}(0, Vector{Int64}[])
SimpleGraph{Int64}
Vector{Any}

MethodError: no method matching EmbeddedGraph(::SimpleGraph{Int64}, ::Vector{Any}, ::EmbeddedGraphs.var"#6#7"{Distances.Euclidean})

Closest candidates are:
  EmbeddedGraph(::SimpleGraph{T}, ::Vector{Vector{Float64}}, ::Function) where T<:Integer
   @ EmbeddedGraphs ~/.julia/packages/EmbeddedGraphs/hxyfT/src/embeddedgraph.jl:19
  EmbeddedGraph(::SimpleGraph, ::Array)
   @ EmbeddedGraphs ~/.julia/packages/EmbeddedGraphs/hxyfT/src/embeddedgraph.jl:23
  EmbeddedGraph(::SimpleGraph, ::Array, ::Distances.Metric)
   @ EmbeddedGraphs ~/.julia/packages/EmbeddedGraphs/hxyfT/src/embeddedgraph.jl:24
  ...


Stacktrace:
 [1] EmbeddedGraph(graph::SimpleGraph{Int64}, vertexpos::Vector{Any}, distance::Distances.Euclidean)
   @ EmbeddedGraphs ~/.julia/packages/EmbeddedGraphs/hxyfT/src/embeddedgraph.jl:24
 [2] EmbeddedGraph(graph::SimpleGraph{Int64}, vertexpos::Vector{Any})
   @ EmbeddedGraphs ~/.julia/packages/EmbeddedGraphs/hxyfT/src/embeddedgraph.jl:23
 [3] regenerate_graph(vertices::Matrix{Float64}, grids_weights_col_ptr::Vector{Int64}, grids_weights_row_val::Vector{Int64})
   @ Main ./In[90]:8
 [4] load_static_test_case(id::String)
   @ Main ./In[68]:9
 [5] simulate_grid(r::Int64)
   @ Main ./In[72]:4
 [6] top-level scope
   @ In[91]:14

Where is that ::EmbeddedGraphs.var"#6#7"{Distances.Euclidean}) coming from? I am so confused!

Addon:

When running

@code_warntype EmbeddedGraph(SimpleGraph(0),[])

I get the following output:

MethodInstance for EmbeddedGraph(::SimpleGraph{Int64}, ::Vector{Any})
  from EmbeddedGraph(graph::SimpleGraph, vertexpos::Array) @ EmbeddedGraphs ~/.julia/packages/EmbeddedGraphs/hxyfT/src/embeddedgraph.jl:23
Arguments
  #self#::Type{EmbeddedGraph}
  graph::SimpleGraph{Int64}
  vertexpos::Vector{Any}
Body::Union{}
1 ─     EmbeddedGraphs.EmbeddedGraph(graph, vertexpos, EmbeddedGraphs.euclidean)
└──     Core.Const(:(return %1))

I’m not acquainted with EmbeddedGraphs.jl, and it seems unmaintained, but giving the coordinate vector an element type seems to help:

julia> EmbeddedGraph(SimpleGraph(0), Vector{Vector{Float64}}())
EmbeddedGraph{Int64}(SimpleGraph{Int64}(0, Vector{Int64}[]), Vector{Float64}[], EmbeddedGraphs.var"#4#5"{Vector{Vector{Float64}}, EmbeddedGraphs.var"#6#7"{Distances.Euclidean}}(Vector{Float64}[], EmbeddedGraphs.var"#6#7"{Distances.Euclidean}(Distances.Euclidean(0.0))))

NB: in case you don’t know, the T[] syntax is basically syntax sugar for Vector{T}(). When the type T is omitted, it basically defaults to Any, meaning there’s no constraint on the element type, which seems to be problematic for EmbeddedGraphs.jl.

tangential, but why not to 1.10?

1 Like

That helped! Thank you so much :slight_smile:

1 Like

Because I forgot to run ‘juliaup update’ :frowning: Thanks for the hint!