Fix sentinel value of opaque pointers in typeInfo

Fixes #3888
This commit is contained in:
LemonBoy 2019-12-19 19:51:57 +01:00 committed by Andrew Kelley
parent f077c3c4cc
commit 51cbd96820
2 changed files with 8 additions and 3 deletions

View File

@ -22689,11 +22689,11 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_ent
// sentinel: var
ensure_field_index(result->type, "sentinel", 6);
fields[6]->special = ConstValSpecialStatic;
fields[6]->type = get_optional_type(ira->codegen, attrs_type->data.pointer.child_type);
if (attrs_type->data.pointer.sentinel != nullptr) {
if (attrs_type->data.pointer.child_type->id != ZigTypeIdOpaque) {
fields[6]->type = get_optional_type(ira->codegen, attrs_type->data.pointer.child_type);
fields[6]->data.x_optional = attrs_type->data.pointer.sentinel;
} else {
fields[6]->data.x_optional = nullptr;
fields[6]->type = ira->codegen->builtin_types.entry_null;
}
return result;

View File

@ -367,3 +367,8 @@ test "data field is a compile-time value" {
};
comptime expect(@typeInfo(S).Struct.decls[0].data.Var == isize);
}
test "sentinel of opaque pointer type" {
const c_void_info = @typeInfo(*c_void);
expect(c_void_info.Pointer.sentinel == null);
}