1 is not a UInt


As typeof(1) == Int64, we have 1 isa UInt == false

However, this makes it difficult to pass a default value:

f(x::UInt = 1) = 2

# MethodError: no method matching f(::Int64)

Sure, I can define:

f(x::UInt = UInt(1)) = 2

but it’s ugly…


It would be a really bad idea for 1 to default to UInt :scream:

I would not expect this to change. Otherwise 1 - 3 would be type unstable or have integer underflow.

1 Like

There is a literal syntax for UInt64, but it is more verbose than typing UInt(1):

julia> 0x0000000000000001 == UInt(1)
1 Like

But the issue here is handling of default parameters.
Why not automatically convert those? They are constants, so this can be done at compile time.

Yeah, open an issue for conversion of literals in defaults. That would be a little magical, but that could happen in that specific context (reminiscent of literal_pow). But the general topic here, 1 is not a UInt, I think is a done deal.

1 Like

This was already discussed. See: dispatch behavior of optional arguments · Issue #7357 · JuliaLang/julia · GitHub