| author | |
| committer | |
| log | 85c863e348d5ba2a1aca3455fefa073047e77e4b |
| tree | 2d1cc5f18a898bf8379e98eaa823f8fa73cafcc8 |
| parent | 4a7f1339ac08bd61ddb6a25127a0ae34dc55c26d |
3 files changed, 9 insertions(+), 3 deletions(-)
src/Sema.zig+1-1| ... | ... | @@ -4253,7 +4253,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 4253 | 4253 | const want_ty = try pt.arrayType(.{ |
| 4254 | 4254 | .len = val_ty.arrayLen(zcu), |
| 4255 | 4255 | .child = elem_ty.toIntern(), |
| 4256 | .sentinel = if (ptr_ty.sentinel(zcu)) |s| s.toIntern() else .none, | |
| 4256 | .sentinel = if (val_ty.sentinel(zcu)) |s| s.toIntern() else .none, | |
| 4257 | 4257 | }); |
| 4258 | 4258 | return sema.coerce(block, want_ty, uncoerced_val, src); |
| 4259 | 4259 | }, |
test/behavior/slice.zig+6| ... | ... | @@ -823,6 +823,12 @@ test "slice sentinel access at comptime" { |
| 823 | 823 | try expect(slice0.len == 3); |
| 824 | 824 | try expect(slice0[slice0.len] == 0); |
| 825 | 825 | } |
| 826 | { | |
| 827 | const slice0: []const u8 = &[_:0]u8{ '1', '2', '3' }; | |
| 828 | ||
| 829 | try expect(slice0.len == 3); | |
| 830 | try expect(slice0.ptr[slice0.len] == 0); | |
| 831 | } | |
| 826 | 832 | } |
| 827 | 833 | |
| 828 | 834 | test "slicing array with sentinel as end index" { |
test/cases/compile_errors/slice_sentinel_mismatch-1.zig+2-2| ... | ... | @@ -10,7 +10,7 @@ export fn entry2() void { |
| 10 | 10 | |
| 11 | 11 | // error |
| 12 | 12 | // |
| 13 | // :2:37: error: expected type '[2:1]u8', found '[2:2]u8' | |
| 14 | // :2:37: note: array sentinel '2' cannot cast into array sentinel '1' | |
| 13 | // :2:29: error: expected type '[:1]const u8', found '*const [2:2]u8' | |
| 14 | // :2:29: note: pointer sentinel '2' cannot cast into pointer sentinel '1' | |
| 15 | 15 | // :7:29: error: expected type '[:1]const u8', found '[:2]const u8' |
| 16 | 16 | // :7:29: note: pointer sentinel '2' cannot cast into pointer sentinel '1' |