Why is this a matching error?


I’m facing this matching error but I simply don’t see why this is not matching…

pull!(item, item2 => 10)
MethodError: no method matching pull!(::Item{Float64,Dirac{Float64},linear_holding_cost{Float64}}, ::Pair{Item{Float64,Dirac{Float64},linear_holding_cost{Int64}},Int64})
  Closest candidates are:
    pull!(::Item, !Matched::Pair{Any,Number}) at /home/dehaybe/Documents/Doctorat/InventoryModels/src/item.jl:36

Oh no okay I get it, the pull! function should be pull!(::Item, Pair{<:Any, <:Number}).
I keep forgetting about that. Maybe the error message could be a bit more guiding ? :face_with_monocle:

Agreed - the problem is that the error message can’t distinguish between mistyped function declarations and “real” mismatch due to some type instability/missing method, so the message should guide to at least those two possibilities. It’s been a topic before, but I can’t seem to find the relevant issue on github.

I guess this must not be a trivial thing to improve :confused:

Any message improvement is better than none! In fact, MethodError has been one of the worst offenders in terms of communicating what’s wrong. If it’s only meant to guide towards potential solutions, I think it’ll have an easier time to be merged, compared to trying to fix all possible cases.

If the formulation is sufficiently suggestive (and not definitive), it’d be very much appreciated. Maybe something like

Potential solutions are:
  * Missing method definition
  * Too strong limitation on argument types
  * Unexpected type at called function

would be a good start for a brainstorming session.