Another odd example:
proc test(n : int) = echo "could be negative"
proc test(n : uint) = echo "must be positive"
test(1)
Run
and
type
I = int | int8 | int16 | int32
UI = uint | uint8 | uint16 | uint32
proc test(n : I) = echo "could be negative"
proc test(n : UI) = echo "must be positive"
let i = 1
test(i)
Run
work as expected.
But
type
I = int | int8 | int16 | int32
UI = uint | uint8 | uint16 | uint32
proc test(n : I) = echo "could be negative"
proc test(n : UI) = echo "must be positive"
test(1)
Run
returns "Error: ambiguous call; both test5.test(n: I) ... and test5.test(n: UI)
... match for: (int literal(1))"
Of course, the compiler behaves as described in "Overloading resolution" in the
manual - but does it make sense?