Skip to content

Commit

Permalink
fix assert when wrapping zero bit type in nullable
Browse files Browse the repository at this point in the history
closes #659
  • Loading branch information
andrewrk committed Dec 19, 2017
1 parent 1435604 commit 1cc450e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type) {
ensure_complete_type(g, child_type);

TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdMaybe);
assert(child_type->type_ref);
assert(child_type->type_ref || child_type->zero_bits);
assert(child_type->di_type);
entry->is_copyable = type_is_copyable(g, child_type);

Expand Down Expand Up @@ -1162,6 +1162,15 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
}

TypeTableEntry *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type);
if (fn_type_id.cc != CallingConventionUnspecified) {
type_ensure_zero_bits_known(g, type_entry);
if (!type_has_bits(type_entry)) {
add_node_error(g, param_node->data.param_decl.type,
buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",
buf_ptr(&type_entry->name), calling_convention_name(fn_type_id.cc)));
return g->builtin_types.entry_invalid;
}
}

switch (type_entry->id) {
case TypeTableEntryIdInvalid:
Expand Down
10 changes: 10 additions & 0 deletions test/compile_errors.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
const tests = @import("tests.zig");

pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("attempt to use 0 bit type in extern fn",
\\extern fn foo(ptr: extern fn(&void));
\\
\\export fn entry() {
\\ foo(bar);
\\}
\\
\\extern fn bar(x: &void) { }
, ".tmp_source.zig:7:18: error: parameter of type '&void' has 0 bits; not allowed in function with calling convention 'ccc'");

cases.add("implicit semicolon - block statement",
\\export fn entry() {
\\ {}
Expand Down

0 comments on commit 1cc450e

Please sign in to comment.