Why 32bit keyword argument functions give error (Int32 also) ?
julia> x = 2
2
julia> function sixty_four(x; y::Float64=0.5)
x+y
end
sixty_four (generic function with 1 method)
julia> function thirty_two(x; y::Float32=0.5)
x+y
end
thirty_two (generic function with 1 method)
julia> sixty_four(x)
2.5
julia> thirty_two(x)
ERROR: MethodError: no method matching var"#thirty_two#2"(::Float64, ::typeof(thirty_two), ::Int64)
The function `#thirty_two#2` exists, but no method is defined for this combination of argument types.
Closest candidates are:
var"#thirty_two#2"(::Float32, ::typeof(thirty_two), ::Any)
@ Main REPL[3]:1
Stacktrace:
[1] thirty_two(x::Int64)
@ Main ./REPL[3]:1
[2] top-level scope
@ REPL[5]:1
Yeah, this seems right. In principle this gives you the liberty to do something like
f(x::Int32 = 1) = x + 1
f(x::Int64) = x - 1
julia> f()
0
but thereβs really no point as you could also just write the much clearer f(x::Int64 = 1) = x - 1.
Depending on how you interpret this, this might also be correct, but let me point out that already during compilation (so not only at runtime) Julia will notice our original f (or thirty_two) does not make sense. For example, we already get
julia> f(x::Int32 = 1) = x
f (generic function with 2 methods)
julia> @code_typed f()
CodeInfo(
1 β builtin Core.throw_methoderror(#self#, 1)::Union{}
βββ unreachable
) => Union{}
dynamic seems to be new as of Julia v1.12. I donβt think we should worry about it, as every function call seems to be dynamic according to @code_lowered. Presumably this is typically no longer relevant further along the lowering/compilation pipeline, but Iβm certainly no expert, so hopefully someone more knowledgeable can chime in.