Yep. Some languages promote to unsigned in this case but that's arbitrary. Another option is to leave it ambiguous. Ditto for Int8 + Int
, etc, or, perhaps even for Int + Int
:
var x: Int16 = ...
var y: UInt16 = ...
let z = x * y // 🛑
let z: Int16 = x * y // ✅ could trap
let z: UInt16 = x * y // ✅ could trap
let z: Int64 = x * y // ✅ can't trap
var w: Int16 = ...
let z = x + w // 🛑
let z: Int16 = x + w // ✅ could trap
let z: Int32 = x + w // ✅ can't trap