authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-02 19:13:21-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-09-02 19:13:21-04:00
logc86108dd63349cbd99a8821fb4d628f31958e0ed
treee68a54f384a8908b37e560cadb11c0a91d6af603
parent405c7215a8054680a789cf94afe41fd66c7d61c7
parentdd4994a4e4379454f6b58779276f1b6aa9ed6e1b
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #6229 from LemonBoy/fix-6054

ir: Typecheck the sentinel value in *[N:S1]T to [S2]T casts

3 files changed, 15 insertions(+), 2 deletions(-)

lib/std/net.zig+1-1
......@@ -1164,7 +1164,7 @@ fn linuxLookupNameFromDnsSearch(
11641164 }
11651165
11661166 const search = if (rc.search.isNull() or dots >= rc.ndots or mem.endsWith(u8, name, "."))
1167 &[_]u8{}
1167 ""
11681168 else
11691169 rc.search.span();
11701170
src/ir.cpp+6-1
......@@ -15341,9 +15341,14 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
1534115341 ZigType *array_type = actual_type->data.pointer.child_type;
1534215342 bool const_ok = (slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0
1534315343 || !actual_type->data.pointer.is_const);
15344
1534415345 if (const_ok && types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type,
1534515346 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))))
1534715352 {
1534815353 // If the pointers both have ABI align, it works.
1534915354 // 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");
22const std = @import("std");
33
44pub 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
513 cases.add("@Type with undefined",
614 \\comptime {
715 \\ _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } });