Yep. When that happens, an exception will be thrown at runtime. Below is a small snippet that demonstrates the behaviour.
var x: int8
# Set the variable like this so the compiler don't
# block the program from compiling.
x = -128
echo abs(x) # throw overflow because 128 doesn't exist for int8.
echo abs(x.int) # this can be handled by first converting the value to a larger type.
Good question!
https://stackoverflow.com/questions/16101062/why-does-stdabs-return-signed-types
That's why C, C++, and C# all return the same type as the argument.
If you write your own library:
proc (int8 x): uint8 =
if x > 0:
return x
else:
return (not cast[uint8](x)) + 1'u8