I was self-studying about specifying the type of inputs of a function.
I came across with this example.
function Date(y::Int64, m::Int64=1, d::Int64=1)
err = validargs(Date, y, m, d)
err === nothing || throw(err)
return Date(UTD(totaldays(y, m, d)))
end
It works perfectly fine. However, when I tried with my own example:
function test(x::Int8,y::Int8)
return x+y
end
test(1,3)
MethodError: no method matching test(::Int64, ::Int64)
Stacktrace:
[1] top-level scope
@ In[38]:5
[2] eval
@ ./boot.jl:360 [inlined]
[3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1116
It turns out that there is an error coming from Int8 . However, I don’t get it because 1 and 3 are both integers in the interval of Int8.