aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorr00ster91 <r00ster91@proton.me>2023-07-03 22:04:30 -0400
committerAndrew Kelley <andrew@ziglang.org>2023-07-10 10:51:55 -0700
commit0b1e8690dadb5d81b4d63832e27a117f57b4be81 (patch)
tree20cc3fb63d08286bd78a1b77b529ff509c5e969a /lib/std
parent3bf0b8eada9ec97d4413fed5be29f5e2af30dce1 (diff)
downloadzig-0b1e8690dadb5d81b4d63832e27a117f57b4be81.tar.gz
zig-0b1e8690dadb5d81b4d63832e27a117f57b4be81.zip
AstGen: make sure for range start and end are usizes
Fixes #16311 The actual cause of #16311 is the `start_is_zero` special case: ```zig const range_len = if (end_val == .none or start_is_zero) end_val else try parent_gz.addPlNode(.sub, input, Zir.Inst.Bin{ .lhs = end_val, .rhs = start_val, }); ``` It only happens if the range start is 0. In that case we would not perform any type checking. Only in the other cases coincidentally `.sub` performs type checking in Sema, but the errors are still rather poor: ``` $ zig test x.zig x.zig:9:15: error: invalid operands to binary expression: 'Pointer' and 'Pointer' for ("abc".."def") |val| { ~~~~~^~~~~~~ ``` Note how it's the same as if I use `-`: ``` x.zig:9:11: error: invalid operands to binary expression: 'Pointer' and 'Pointer' "abc" - "def"; ~~~~~~^~~~~~~ ``` Now after this PR, the errors are much clearer for both range start and end: ``` x.zig:9:10: error: expected type 'usize', found '*const [3:0]u8' for ("abc".."def") |val| { ^~~~~ ``` This is why I decided to use `.ty` instead of `.coerced_ty` for both range start and end rather than just perform type checking in that `end_val == .none or start_is_zero` case.
Diffstat (limited to 'lib/std')
0 files changed, 0 insertions, 0 deletions