add compile error for function prototype with no body

closes #1231
master
Andrew Kelley 2018-08-28 15:39:32 -04:00
parent 09cc1dc660
commit 901b5c1566
No known key found for this signature in database
GPG Key ID: 4E7CD66038A4D47C
2 changed files with 17 additions and 0 deletions

View File

@ -3242,6 +3242,13 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
} else if (tld->id == TldIdFn) {
assert(tld->source_node->type == NodeTypeFnProto);
is_export = tld->source_node->data.fn_proto.is_export;
if (!is_export && !tld->source_node->data.fn_proto.is_extern &&
tld->source_node->data.fn_proto.fn_def_node == nullptr)
{
add_node_error(g, tld->source_node, buf_sprintf("non-extern function has no body"));
return;
}
}
if (is_export) {
g->resolve_queue.append(tld);

View File

@ -1,6 +1,16 @@
const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"function protoype with no body",
\\fn foo() void;
\\export fn entry() void {
\\ foo();
\\}
,
".tmp_source.zig:1:1: error: non-extern function has no body",
);
cases.add(
"@typeInfo causing depend on itself compile error",
\\const start = struct {