aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandros Naskos <alex_naskos@hotmail.com>2018-06-14 17:57:28 +0300
committerAndrew Kelley <superjoe30@gmail.com>2018-06-14 10:57:28 -0400
commit4ec09ac243afa0b784669e618ec09e9e444a0275 (patch)
treea42c343a2b0d5b884f3ac377ba392a8cd9f99c7f
parentfc87f6e417d206a88b581b77d3a5494ae4c978dd (diff)
downloadzig-4ec09ac243afa0b784669e618ec09e9e444a0275.tar.gz
zig-4ec09ac243afa0b784669e618ec09e9e444a0275.zip
Enabled optional types of zero bit types with no LLVM DI type. (#1110)
* Zero bit optional types do not need a LLVM DI type
-rw-r--r--src/analyze.cpp3
-rw-r--r--test/cases/null.zig11
2 files changed, 13 insertions, 1 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 0aa5ea5dcb..cbeac7bc21 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -522,7 +522,6 @@ TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type) {
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdOptional);
assert(child_type->type_ref || child_type->zero_bits);
- assert(child_type->di_type);
entry->is_copyable = type_is_copyable(g, child_type);
buf_resize(&entry->name, 0);
@@ -532,12 +531,14 @@ TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type) {
entry->type_ref = LLVMInt1Type();
entry->di_type = g->builtin_types.entry_bool->di_type;
} else if (type_is_codegen_pointer(child_type)) {
+ assert(child_type->di_type);
// this is an optimization but also is necessary for calling C
// functions where all pointers are maybe pointers
// function types are technically pointers
entry->type_ref = child_type->type_ref;
entry->di_type = child_type->di_type;
} else {
+ assert(child_type->di_type);
// create a struct with a boolean whether this is the null value
LLVMTypeRef elem_types[] = {
child_type->type_ref,
diff --git a/test/cases/null.zig b/test/cases/null.zig
index cdcfd23efb..d2a9aaed55 100644
--- a/test/cases/null.zig
+++ b/test/cases/null.zig
@@ -143,3 +143,14 @@ test "null with default unwrap" {
const x: i32 = null orelse 1;
assert(x == 1);
}
+
+test "optional types" {
+ comptime {
+ const opt_type_struct = StructWithOptionalType { .t=u8, };
+ assert(opt_type_struct.t != null and opt_type_struct.t.? == u8);
+ }
+}
+
+const StructWithOptionalType = struct {
+ t: ?type,
+};