Closed
Description
The following code works correctly
julia> f{T<:Number}(x::T, y...) = (println(length(y)); f(y[1], y[2:end]...))
f (generic function with 1 method)
julia> f{T<:Number}(x::T) = "hi"
f (generic function with 2 methods)
julia> f(1,rand(10)...)
10
9
8
7
6
5
4
3
2
1
"hi"
But it fails when I change to <:Union the parametrization
julia> f{T<:Union{Float32,Float64}}(x::T, y...) = (println(length(y)); f(y[1], y[2:end]...))
f (generic function with 1 method)
julia> f{T<:Union{Float32,Float64}}(x::T) = "hi"
f (generic function with 2 methods)
julia> f(1.,rand(10)...)
10
9
8
7
6
5
4
3
2
1
0
ERROR: BoundsError: attempt to access ()
at index [1]
in f(::Float64) at ./REPL[1]:1 (repeats 11 times)
in eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:64
in macro expansion at ./REPL.jl:95 [inlined]
in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at ./event.jl:68
At the last step we have a wrong dispatch to the first method instead of the second
Bye,
Carlo
Activity