julia icon indicating copy to clipboard operation
julia copied to clipboard

Signature of `invoke` in the docstring seems misleading

Open jishnub opened this issue 2 years ago • 1 comments

https://github.com/JuliaLang/julia/blob/742b9abb4dd4621b667ec5bb3434b8b3602f96fd/base/docs/basedocs.jl#L1657

The type assertion on the second argument seems to indicate that the type T of the input argument should be passed, but in reality it's Tuple{T}. E.g:

julia> f(x::Int) = 2
f (generic function with 1 method)

julia> invoke(f, Int, 2)
ERROR: TypeError: in invoke, expected Type{T} where T<:Tuple, got Type{Int64}
Stacktrace:
 [1] top-level scope
   @ REPL[9]:1

julia> invoke(f, Tuple{Int}, 2)
2

This ambiguity is of course only for the 1-argument case, and the examples make the usage clear. However, maybe the assertion should be changed to reflect this as well.

jishnub avatar Aug 08 '22 14:08 jishnub

How about the variadic tuple type

invoke(f, argtypes::Tuple{Vararg{Any}}, args...; kwargs...)

?

mgkuhn avatar Aug 08 '22 18:08 mgkuhn