| author | |
| committer | |
| log | fb43e91b226a9cde51967455c57989c0371d4b0a |
| tree | c411f5cbbbf9b162dd3bdc8b4b494145cc91cca7 |
| parent | 5de880c288b0f340b57442d68685c79cf515fc78 |
| signature |
3 files changed, 58 insertions(+), 14 deletions(-)
src/Sema.zig+3| ... | @@ -8423,6 +8423,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil | ... | @@ -8423,6 +8423,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 8423 | .sentinel = sentinel_val.toIntern(), | 8423 | .sentinel = sentinel_val.toIntern(), |
| 8424 | .child = elem_type.toIntern(), | 8424 | .child = elem_type.toIntern(), |
| 8425 | }); | 8425 | }); |
| 8426 | try sema.checkSentinelType(block, sentinel_src, elem_type); | ||
| 8426 | 8427 | ||
| 8427 | return Air.internedToRef(array_ty.toIntern()); | 8428 | return Air.internedToRef(array_ty.toIntern()); |
| 8428 | } | 8429 | } |
| ... | @@ -21650,6 +21651,7 @@ fn zirReify( | ... | @@ -21650,6 +21651,7 @@ fn zirReify( |
| 21650 | const sentinel_ptr_val = sentinel_val.optionalValue(zcu).?; | 21651 | const sentinel_ptr_val = sentinel_val.optionalValue(zcu).?; |
| 21651 | const ptr_ty = try pt.singleMutPtrType(elem_ty); | 21652 | const ptr_ty = try pt.singleMutPtrType(elem_ty); |
| 21652 | const sent_val = (try sema.pointerDeref(block, src, sentinel_ptr_val, ptr_ty)).?; | 21653 | const sent_val = (try sema.pointerDeref(block, src, sentinel_ptr_val, ptr_ty)).?; |
| 21654 | try sema.checkSentinelType(block, src, elem_ty); | ||
| 21653 | break :s sent_val.toIntern(); | 21655 | break :s sent_val.toIntern(); |
| 21654 | } | 21656 | } |
| 21655 | break :s .none; | 21657 | break :s .none; |
| ... | @@ -21714,6 +21716,7 @@ fn zirReify( | ... | @@ -21714,6 +21716,7 @@ fn zirReify( |
| 21714 | const child_ty = child_val.toType(); | 21716 | const child_ty = child_val.toType(); |
| 21715 | const sentinel = if (sentinel_val.optionalValue(zcu)) |p| blk: { | 21717 | const sentinel = if (sentinel_val.optionalValue(zcu)) |p| blk: { |
| 21716 | const ptr_ty = try pt.singleMutPtrType(child_ty); | 21718 | const ptr_ty = try pt.singleMutPtrType(child_ty); |
| 21719 | try sema.checkSentinelType(block, src, child_ty); | ||
| 21717 | break :blk (try sema.pointerDeref(block, src, p, ptr_ty)).?; | 21720 | break :blk (try sema.pointerDeref(block, src, p, ptr_ty)).?; |
| 21718 | } else null; | 21721 | } else null; |
| 21719 | 21722 |
test/cases/compile_errors/array slice sentinel mismatch non-scalar.zig	 deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | export fn foo() void { | ||
| 2 | const S = struct { a: u32 }; | ||
| 3 | const sentinel: S = .{ .a = 1 }; | ||
| 4 | var arr = [_]S{ .{ .a = 1 }, .{ .a = 2 } }; | ||
| 5 | const s = arr[0..1 :sentinel]; | ||
| 6 | _ = s; | ||
| 7 | } | ||
| 8 | |||
| 9 | // error | ||
| 10 | // backend=stage2 | ||
| 11 | // target=native | ||
| 12 | // | ||
| 13 | // :5:25: error: non-scalar sentinel type 'tmp.foo.S' | ||
| 14 | // :2:15: note: struct declared here | ||
test/cases/compile_errors/non_scalar_sentinel.zig created+55| ... | @@ -0,0 +1,55 @@ | ||
| 1 | const S = struct {}; | ||
| 2 | const sentinel: S = .{}; | ||
| 3 | |||
| 4 | comptime { | ||
| 5 | _ = [0:sentinel]S; | ||
| 6 | } | ||
| 7 | comptime { | ||
| 8 | _ = [:sentinel]S; | ||
| 9 | } | ||
| 10 | comptime { | ||
| 11 | _ = [*:sentinel]S; | ||
| 12 | } | ||
| 13 | |||
| 14 | comptime { | ||
| 15 | _ = @Type(.{ .array = .{ .child = S, .len = 0, .sentinel = &sentinel } }); | ||
| 16 | } | ||
| 17 | comptime { | ||
| 18 | _ = @Type(.{ .pointer = .{ | ||
| 19 | .size = .Many, | ||
| 20 | .is_const = false, | ||
| 21 | .is_volatile = false, | ||
| 22 | .alignment = @alignOf(S), | ||
| 23 | .address_space = .generic, | ||
| 24 | .child = S, | ||
| 25 | .is_allowzero = false, | ||
| 26 | .sentinel = &sentinel, | ||
| 27 | } }); | ||
| 28 | } | ||
| 29 | comptime { | ||
| 30 | _ = @Type(.{ .pointer = .{ | ||
| 31 | .size = .Many, | ||
| 32 | .is_const = false, | ||
| 33 | .is_volatile = false, | ||
| 34 | .alignment = @alignOf(S), | ||
| 35 | .address_space = .generic, | ||
| 36 | .child = S, | ||
| 37 | .is_allowzero = false, | ||
| 38 | .sentinel = &sentinel, | ||
| 39 | } }); | ||
| 40 | } | ||
| 41 | |||
| 42 | // error | ||
| 43 | // | ||
| 44 | // :5:12: error: non-scalar sentinel type 'tmp.S' | ||
| 45 | // :1:11: note: struct declared here | ||
| 46 | // :8:11: error: non-scalar sentinel type 'tmp.S' | ||
| 47 | // :1:11: note: struct declared here | ||
| 48 | // :11:12: error: non-scalar sentinel type 'tmp.S' | ||
| 49 | // :1:11: note: struct declared here | ||
| 50 | // :15:9: error: non-scalar sentinel type 'tmp.S' | ||
| 51 | // :1:11: note: struct declared here | ||
| 52 | // :18:9: error: non-scalar sentinel type 'tmp.S' | ||
| 53 | // :1:11: note: struct declared here | ||
| 54 | // :30:9: error: non-scalar sentinel type 'tmp.S' | ||
| 55 | // :1:11: note: struct declared here | ||