Skip to content

Commit 4ec09ac

Browse files
alexnaskandrewrk
authored andcommittedJun 14, 2018
Enabled optional types of zero bit types with no LLVM DI type. (#1110)
* Zero bit optional types do not need a LLVM DI type
·
0.15.20.3.0
1 parent fc87f6e commit 4ec09ac

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed
 

‎src/analyze.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,6 @@ TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type) {
522522

523523
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdOptional);
524524
assert(child_type->type_ref || child_type->zero_bits);
525-
assert(child_type->di_type);
526525
entry->is_copyable = type_is_copyable(g, child_type);
527526

528527
buf_resize(&entry->name, 0);
@@ -532,12 +531,14 @@ TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type) {
532531
entry->type_ref = LLVMInt1Type();
533532
entry->di_type = g->builtin_types.entry_bool->di_type;
534533
} else if (type_is_codegen_pointer(child_type)) {
534+
assert(child_type->di_type);
535535
// this is an optimization but also is necessary for calling C
536536
// functions where all pointers are maybe pointers
537537
// function types are technically pointers
538538
entry->type_ref = child_type->type_ref;
539539
entry->di_type = child_type->di_type;
540540
} else {
541+
assert(child_type->di_type);
541542
// create a struct with a boolean whether this is the null value
542543
LLVMTypeRef elem_types[] = {
543544
child_type->type_ref,

‎test/cases/null.zig‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,14 @@ test "null with default unwrap" {
143143
const x: i32 = null orelse 1;
144144
assert(x == 1);
145145
}
146+
147+
test "optional types" {
148+
comptime {
149+
const opt_type_struct = StructWithOptionalType { .t=u8, };
150+
assert(opt_type_struct.t != null and opt_type_struct.t.? == u8);
151+
}
152+
}
153+
154+
const StructWithOptionalType = struct {
155+
t: ?type,
156+
};

0 commit comments

Comments
 (0)
Please sign in to comment.