diff options
| author | Techatrix <techatrix@mailbox.org> | 2024-12-29 06:47:15 +0100 |
|---|---|---|
| committer | Techatrix <techatrix@mailbox.org> | 2024-12-29 07:00:39 +0100 |
| commit | 5b6326ec6540d1b7af8de1176f657672be72a1e4 (patch) | |
| tree | 60d3a3c3ad1f5c68d12c33ae7b4181af9331fc1c /lib/std | |
| parent | 5d51d4474a0c61f08c264c03ecbdf651d91afe82 (diff) | |
| download | zig-5b6326ec6540d1b7af8de1176f657672be72a1e4.tar.gz zig-5b6326ec6540d1b7af8de1176f657672be72a1e4.zip | |
fix slice of slice with sentinel on the lhs slice
example:
```zig
test {
var foo: [2:0]u8 = .{ 1, 2 };
_ = foo[0.. :1][0..2];
}
```
A `.slice_open` ast node will not have a end index nor sentinel.
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/zig/AstGen.zig | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/lib/std/zig/AstGen.zig b/lib/std/zig/AstGen.zig index 90d88d0d78..6e424b597f 100644 --- a/lib/std/zig/AstGen.zig +++ b/lib/std/zig/AstGen.zig @@ -881,21 +881,14 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE .slice_sentinel, => { const full = tree.fullSlice(node).?; - const lhs_tag = node_tags[full.ast.sliced]; - const lhs_is_slice_sentinel = lhs_tag == .slice_sentinel; - const lhs_is_open_slice = lhs_tag == .slice_open or - (lhs_is_slice_sentinel and tree.fullSlice(full.ast.sliced).?.ast.end == 0); if (full.ast.end != 0 and - lhs_is_open_slice and + node_tags[full.ast.sliced] == .slice_open and nodeIsTriviallyZero(tree, full.ast.start)) { - const lhs = try expr(gz, scope, .{ .rl = .ref }, node_datas[full.ast.sliced].lhs); - - const start = if (lhs_is_slice_sentinel) start: { - const lhs_extra = tree.extraData(node_datas[full.ast.sliced].rhs, Ast.Node.SliceSentinel); - break :start try expr(gz, scope, .{ .rl = .{ .coerced_ty = .usize_type } }, lhs_extra.start); - } else try expr(gz, scope, .{ .rl = .{ .coerced_ty = .usize_type } }, node_datas[full.ast.sliced].rhs); + const lhs_extra = tree.sliceOpen(full.ast.sliced).ast; + const lhs = try expr(gz, scope, .{ .rl = .ref }, lhs_extra.sliced); + const start = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .usize_type } }, lhs_extra.start); const cursor = maybeAdvanceSourceCursorToMainToken(gz, node); const len = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .usize_type } }, full.ast.end); const sentinel = if (full.ast.sentinel != 0) try expr(gz, scope, .{ .rl = .none }, full.ast.sentinel) else .none; |
