| author | |
| committer | |
| log | c86108dd63349cbd99a8821fb4d628f31958e0ed |
| tree | e68a54f384a8908b37e560cadb11c0a91d6af603 |
| parent | 405c7215a8054680a789cf94afe41fd66c7d61c7 |
| parent | dd4994a4e4379454f6b58779276f1b6aa9ed6e1b |
| signature |
ir: Typecheck the sentinel value in *[N:S1]T to [S2]T casts3 files changed, 15 insertions(+), 2 deletions(-)
lib/std/net.zig+1-1| ... | ... | @@ -1164,7 +1164,7 @@ fn linuxLookupNameFromDnsSearch( |
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | 1166 | const search = if (rc.search.isNull() or dots >= rc.ndots or mem.endsWith(u8, name, ".")) |
| 1167 | &[_]u8{} | |
| 1167 | "" | |
| 1168 | 1168 | else |
| 1169 | 1169 | rc.search.span(); |
| 1170 | 1170 |
src/ir.cpp+6-1| ... | ... | @@ -15341,9 +15341,14 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 15341 | 15341 | ZigType *array_type = actual_type->data.pointer.child_type; |
| 15342 | 15342 | bool const_ok = (slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0 |
| 15343 | 15343 | || !actual_type->data.pointer.is_const); |
| 15344 | ||
| 15344 | 15345 | if (const_ok && types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type, |
| 15345 | 15346 | array_type->data.array.child_type, source_node, |
| 15346 | !slice_ptr_type->data.pointer.is_const).id == ConstCastResultIdOk) | |
| 15347 | !slice_ptr_type->data.pointer.is_const).id == ConstCastResultIdOk && | |
| 15348 | (slice_ptr_type->data.pointer.sentinel == nullptr || | |
| 15349 | (array_type->data.array.sentinel != nullptr && | |
| 15350 | const_values_equal(ira->codegen, array_type->data.array.sentinel, | |
| 15351 | slice_ptr_type->data.pointer.sentinel)))) | |
| 15347 | 15352 | { |
| 15348 | 15353 | // If the pointers both have ABI align, it works. |
| 15349 | 15354 | // Or if the array length is 0, alignment doesn't matter. |
test/compile_errors.zig+8| ... | ... | @@ -2,6 +2,14 @@ const tests = @import("tests.zig"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | |
| 4 | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.add("slice sentinel mismatch", | |
| 6 | \\export fn entry() void { | |
| 7 | \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 }; | |
| 8 | \\} | |
| 9 | , &[_][]const u8{ | |
| 10 | "tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'", | |
| 11 | }); | |
| 12 | ||
| 5 | 13 | cases.add("@Type with undefined", |
| 6 | 14 | \\comptime { |
| 7 | 15 | \\ _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } }); |