d = (Bool=>Int8)
d[true] = 2345 # => 2345
d[true] # => 41
The culprit lies here. The key is checked for truncation, but not the value.
We could check that values are isequal after conversion for Dicts without incurring substantial overhead relative to the cost of hashing, but I'm not sure that really makes sense, since Arrays do the same thing:
julia> d = Array(Int8, 1);
julia> d = 2345
The underlying reason for this behavior is that convert(Int8, 2345) doesn't throw, even though 2345 can't be expressed as an Int8. This came up previously in #4166 and @StefanKarpinski expressed some misgivings about the present convert behavior, but we decided not to change it then.
Yes, this is about convert truncating integers. Given the definition of convert, it is clear that this is incorrect, but it just happens that one very often wants to truncate integers. We should probably bite the bullet and change it.
See also #7517. When this is changed, itrunc should be changed too.
check integer truncation (#5413) and make more operators follow T+T =…
…> T (#3759)
the sysimg builds, but still need to:
- check same-size signed<->unsigned conversion
- make tests pass
closed by #8420