Skip to content

Commit 1cc450e

Browse files
committedDec 19, 2017
fix assert when wrapping zero bit type in nullable
closes #659
·
0.15.20.2.0
1 parent 1435604 commit 1cc450e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
 

‎src/analyze.cpp‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
const tests = @import("tests.zig");
22

33
pub 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
\\ {}

0 commit comments

Comments
 (0)
Please sign in to comment.