It seems to me that the dispatch system is doing something wrong. Apologies ahead of time if there’s something blindingly obvious that I’m missing here.
See the examples below:
This is as expected:
function func(
x::Vector{Char};
convert::Bool=true,
)
println("x=$x")
end
x = "julia" |> collect # typeof Vector{Char}
func(x) # this line prints: x=['j', 'u', 'l', 'i', 'a']
But what’s going on here?!
function func(
x::Vector{Char};
convert::Bool=true,
other::Vector{String}=[],
)
println("x=$x")
end
x = "julia" |> collect
func(x)
# ERROR: MethodError: no method matching var"#func#44"(::Bool, ::Vector{Any}, ::typeof(func), ::Vector{Char})
# Closest candidates are:
# var"#func#44"(::Bool, ::Vector{String}, ::typeof(func), ::Vector{Char}) at ~/repos/test_arrow_compression.jl:30
It tells me no method matching func(::Bool,...
which I’m not trying to call and suggests that the closest candidate is func(::Bool...
which doesn’t exist. I suspect this Bool comes from the convert
kwarg.
In the process of building this minimal example I actually found a way of making it work:
function func(
x::Vector{Char};
convert::Bool=true,
other::Vector{String}=String[],
)
println("x=$x")
end
x = "julia" |> collect
func(x) # this line prints: x=['j', 'u', 'l', 'i', 'a']
If you’ll make experiments with this, make sure you clear the function each time so that the experiments are independent:
for m in Base.methods(func)
Base.delete_method(m)
end
I’ve checked that this happens with both 1.8.5
and 1.9.0-rc1
:
julia> versioninfo()
Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 8 × Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-13.0.1 (ORCJIT, skylake)
Threads: 1 on 8 virtual cores
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS =