commit 1cc450e6e70008eb2eaf62f2992d9d3e8b3ab87a (tree)
parent 1435604b84dbf338c1b6096f473bc89aef144be0
Author: Andrew Kelley <superjoe30@gmail.com>
Date: Tue, 19 Dec 2017 18:21:42 -0500
fix assert when wrapping zero bit type in nullable
closes #659
Diffstat:
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/src/analyze.cpp b/src/analyze.cpp
@@ -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);
@@ -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:
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
@@ -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() {
\\ {}