zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 673a1efa228f1e28317c202b8ab9135afb9ed2a2 (tree)
parent b1730880894493d7cd9b1b7bc06e49c9120ca7b6
Author: David <87927264+Rexicon226@users.noreply.github.com>
Date:   Thu, 16 Nov 2023 08:08:30 -0800

Sema: include sentinel in type of pointer-to-array `ptr` field

Resolves: #18007
Diffstat:
Msrc/Sema.zig | 2+-
Mtest/behavior/string_literals.zig | 6++++++
2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -26089,7 +26089,7 @@ fn fieldVal( const ptr_info = object_ty.ptrInfo(mod); const result_ty = try sema.ptrType(.{ .child = ptr_info.child.toType().childType(mod).toIntern(), - .sentinel = ptr_info.sentinel, + .sentinel = if (inner_ty.sentinel(mod)) |s| s.toIntern() else .none, .flags = .{ .size = .Many, .alignment = ptr_info.flags.alignment, diff --git a/test/behavior/string_literals.zig b/test/behavior/string_literals.zig @@ -74,3 +74,9 @@ test "@src() returns a struct containing 0-terminated string slices" { const ptr_src_fn_name: [*:0]const u8 = src.fn_name; _ = ptr_src_fn_name; // unused } + +test "string literal pointer sentinel" { + const string_literal = "something"; + + try std.testing.expect(@TypeOf(string_literal.ptr) == [*:0]const u8); +}