authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2023-11-16 08:08:30-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-11-16 16:08:30+00:00
log673a1efa228f1e28317c202b8ab9135afb9ed2a2
tree1cc2c251fb44892ddeb3fa2d4bb606f7de3b692d
parentb1730880894493d7cd9b1b7bc06e49c9120ca7b6
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

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

Resolves: #18007

2 files changed, 7 insertions(+), 1 deletions(-)

src/Sema.zig+1-1
......@@ -26089,7 +26089,7 @@ fn fieldVal(
2608926089 const ptr_info = object_ty.ptrInfo(mod);
2609026090 const result_ty = try sema.ptrType(.{
2609126091 .child = ptr_info.child.toType().childType(mod).toIntern(),
26092 .sentinel = ptr_info.sentinel,
26092 .sentinel = if (inner_ty.sentinel(mod)) |s| s.toIntern() else .none,
2609326093 .flags = .{
2609426094 .size = .Many,
2609526095 .alignment = ptr_info.flags.alignment,
test/behavior/string_literals.zig+6
......@@ -74,3 +74,9 @@ test "@src() returns a struct containing 0-terminated string slices" {
7474 const ptr_src_fn_name: [*:0]const u8 = src.fn_name;
7575 _ = ptr_src_fn_name; // unused
7676}
77
78test "string literal pointer sentinel" {
79 const string_literal = "something";
80
81 try std.testing.expect(@TypeOf(string_literal.ptr) == [*:0]const u8);
82}