RLS could be more sophisticated for sure. I hit this recently:
var buf: [256]u8 = undefined;
var buf_alloc = FixedBufferAllocator.init(&buf);
const alloc = buf_alloc.allocator();
The only reason buf_alloc exists is because of the const default, so I have to cast it to var instead of just this:
var buf: [256]u8 = undefined;
const alloc = FixedBufferAllocator.init(&buf).allocator();
Analysis of the whole expression would reveal that the chaining is perfectly legal. The compiler just needs to be a bit lazier about assigning constness to intermediate expressions.
This, however:
Is a downcast. Half of the legal values of a u32 aren’t representable in i32. C’s loose rules around promotion can lead to absolutely teeth-grinding bugs, which are difficult to surface and correct.
That said, downcasting does happen a lot. A builtin @downCast(i32, y) would be a good compromise here.