| author | |
| committer | |
| log | b5e72c0148e40df418bdc8e1770b1bd42e76732e |
| tree | 69c741c4fcc2bef40e7b6031ae6eea25b67588db |
| parent | 173a143dd04f9ec75355c04be9b0e6353ee9bc03 |
Changing the pointer length from Unknown to Single/C now resets the
sentinel value too.
Closes #51343 files changed, 10 insertions(+), 3 deletions(-)
src/analyze.cpp+1| ... | ... | @@ -578,6 +578,7 @@ ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_con |
| 578 | 578 | } |
| 579 | 579 | switch (ptr_len) { |
| 580 | 580 | case PtrLenSingle: |
| 581 | assert(sentinel == nullptr); | |
| 581 | 582 | buf_appendf(&entry->name, "*"); |
| 582 | 583 | break; |
| 583 | 584 | case PtrLenUnknown: |
src/ir.cpp+1-1| ... | ... | @@ -21090,7 +21090,7 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) { |
| 21090 | 21090 | ptr_type->data.pointer.allow_zero, |
| 21091 | 21091 | ptr_type->data.pointer.vector_index, |
| 21092 | 21092 | ptr_type->data.pointer.inferred_struct_field, |
| 21093 | ptr_type->data.pointer.sentinel); | |
| 21093 | (ptr_len != PtrLenUnknown) ? nullptr : ptr_type->data.pointer.sentinel); | |
| 21094 | 21094 | } |
| 21095 | 21095 | |
| 21096 | 21096 | static ZigType *adjust_ptr_allow_zero(CodeGen *g, ZigType *ptr_type, bool allow_zero) { |
test/stage1/behavior/pointers.zig+8-2| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const expect = std.testing.expect; | |
| 3 | const expectError = std.testing.expectError; | |
| 2 | const testing = std.testing; | |
| 3 | const expect = testing.expect; | |
| 4 | const expectError = testing.expectError; | |
| 4 | 5 | |
| 5 | 6 | test "dereference pointer" { |
| 6 | 7 | comptime testDerefPtr(); |
| ... | ... | @@ -331,3 +332,8 @@ test "@ptrToInt on null optional at comptime" { |
| 331 | 332 | comptime expect(0xf00 == @ptrToInt(pointer)); |
| 332 | 333 | } |
| 333 | 334 | } |
| 335 | ||
| 336 | test "indexing array with sentinel returns correct type" { | |
| 337 | var s: [:0]const u8 = "abc"; | |
| 338 | testing.expectEqualSlices(u8, "*const u8", @typeName(@TypeOf(&s[0]))); | |
| 339 | } |