stage1: Prevent the creation of illegal pointer types
Changing the pointer length from Unknown to Single/C now resets the sentinel value too. Closes #5134
This commit is contained in:
parent
173a143dd0
commit
b5e72c0148
@ -578,6 +578,7 @@ ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_con
|
||||
}
|
||||
switch (ptr_len) {
|
||||
case PtrLenSingle:
|
||||
assert(sentinel == nullptr);
|
||||
buf_appendf(&entry->name, "*");
|
||||
break;
|
||||
case PtrLenUnknown:
|
||||
|
@ -21090,7 +21090,7 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) {
|
||||
ptr_type->data.pointer.allow_zero,
|
||||
ptr_type->data.pointer.vector_index,
|
||||
ptr_type->data.pointer.inferred_struct_field,
|
||||
ptr_type->data.pointer.sentinel);
|
||||
(ptr_len != PtrLenUnknown) ? nullptr : ptr_type->data.pointer.sentinel);
|
||||
}
|
||||
|
||||
static ZigType *adjust_ptr_allow_zero(CodeGen *g, ZigType *ptr_type, bool allow_zero) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectError = std.testing.expectError;
|
||||
const testing = std.testing;
|
||||
const expect = testing.expect;
|
||||
const expectError = testing.expectError;
|
||||
|
||||
test "dereference pointer" {
|
||||
comptime testDerefPtr();
|
||||
@ -331,3 +332,8 @@ test "@ptrToInt on null optional at comptime" {
|
||||
comptime expect(0xf00 == @ptrToInt(pointer));
|
||||
}
|
||||
}
|
||||
|
||||
test "indexing array with sentinel returns correct type" {
|
||||
var s: [:0]const u8 = "abc";
|
||||
testing.expectEqualSlices(u8, "*const u8", @typeName(@TypeOf(&s[0])));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user