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

Resolves: #18007
This commit is contained in:
David 2023-11-16 08:08:30 -08:00 committed by GitHub
parent b173088089
commit 673a1efa22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -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,

View File

@ -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);
}