Multiple dispatch causes warntype in closure?

It’s the same issue from this earlier topic you posted: Strange @code_warntype - #10 by kristoffer.carlsson

You can work around the issue by explicitly capturing f in a let block:

julia> function generator1()::Function
           function f(x::Vector{Int64})
               return sum(x)
           end

           function f(x::Matrix{Int64})
               return prod(x)
           end

           g = let f_ = f
             function(xx)
               f_(xx) + 1
             end
           end

           return g
       end
2 Likes