Commit 673a1efa22

David <87927264+Rexicon226@users.noreply.github.com>
2023-11-16 17:08:30
Sema: include sentinel in type of pointer-to-array `ptr` field
Resolves: #18007
1 parent b173088
Changed files (2)
src
test
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,
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);
+}