JuliaTesting/Mocking.jl

Patches for functions with anonymous arguments

Closed this issue · 0 comments

I'm getting the following error when patching functions with anonymous arguments:

julia> using Mocking
julia> f{T <: Unsigned}(::Type{T}, n::Int64) = rand(T, n)
f (generic function with 1 method)

julia> f(UInt8, 2)
2-element Array{UInt8,1}:
 0x77
 0x4c

julia> patch = @patch f(::Type{UInt8}, n::Int64) = [0x01, 0x02]
ERROR: BoundsError: attempt to access 1-element Array{Any,1} at index [2]

Of course, a simple workaround is to name the argument, e.g.

julia> patch = @patch f(t::Type{UInt8}, n::Int64) = [0x01, 0x02]
Mocking.Patch(:(f(t::Core.Type,n::Core.Int64)),##271,Set(Symbol[:Core]))