I can understand the reason for raising a warning or error when you try to convert a wider integer type to a narrower one, due to the loss of precision.Some C compilers will warn about this:
uint32_t x = 100000;uint16_t y = x;
Swift raises an error:
let y: UInt32 = 100000let x: UInt16 = y // error: cannot convert value of type 'UInt32' to specified type 'UInt16'
Swift also prevents widening implicit conversions even though there is no possibility for overflow or loss of precision:
let y: UInt16 = 100000let x: UInt32 = y // error: cannot convert value of type 'UInt16' to specified type 'UInt32'
Are there any drawbacks to implicit widening conversions? In what cases could allowing them impact program correctness?