authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-19 18:21:42-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-19 18:21:42-05:00
log1cc450e6e70008eb2eaf62f2992d9d3e8b3ab87a
tree6e7b3c3dc93acb1e70dc5d6d952b185d984b2b97
parent1435604b84dbf338c1b6096f473bc89aef144be0

fix assert when wrapping zero bit type in nullable

closes #659

2 files changed, 20 insertions(+), 1 deletions(-)

src/analyze.cpp+10-1
......@@ -429,7 +429,7 @@ TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type) {
429429 ensure_complete_type(g, child_type);
430430
431431 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdMaybe);
432 assert(child_type->type_ref);
432 assert(child_type->type_ref || child_type->zero_bits);
433433 assert(child_type->di_type);
434434 entry->is_copyable = type_is_copyable(g, child_type);
435435
......@@ -1162,6 +1162,15 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
11621162 }
11631163
11641164 TypeTableEntry *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type);
1165 if (fn_type_id.cc != CallingConventionUnspecified) {
1166 type_ensure_zero_bits_known(g, type_entry);
1167 if (!type_has_bits(type_entry)) {
1168 add_node_error(g, param_node->data.param_decl.type,
1169 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",
1170 buf_ptr(&type_entry->name), calling_convention_name(fn_type_id.cc)));
1171 return g->builtin_types.entry_invalid;
1172 }
1173 }
11651174
11661175 switch (type_entry->id) {
11671176 case TypeTableEntryIdInvalid:
test/compile_errors.zig+10
......@@ -1,6 +1,16 @@
11const tests = @import("tests.zig");
22
33pub fn addCases(cases: &tests.CompileErrorContext) {
4 cases.add("attempt to use 0 bit type in extern fn",
5 \\extern fn foo(ptr: extern fn(&void));
6 \\
7 \\export fn entry() {
8 \\ foo(bar);
9 \\}
10 \\
11 \\extern fn bar(x: &void) { }
12 , ".tmp_source.zig:7:18: error: parameter of type '&void' has 0 bits; not allowed in function with calling convention 'ccc'");
13
414 cases.add("implicit semicolon - block statement",
515 \\export fn entry() {
616 \\ {}