Oof. It’d be nice if that return @min(200, x) + 100 could propagate the result type to the operands of + so that it becomes equivalent to return @as(u16, @min(200, x)) + @as(u16, 100) (there’s probably issues with that suggestion that I haven’t considered).
EDIT: Removed the link to the PTR removal proposal, I think the issue would still exist even with it gone.
It’s unfortunate that Zig’s safety-checked integer arithmetic in combination with implicit, reader-invisible types makes it so easy to shoot yourself in the foot. I really hope that ranged integer types (allow integer types to be any range · Issue #3806 · ziglang/zig · GitHub) with implicit widening arithmetic and explicit narrowing will happen, it would eliminate an entire class of footgun.