authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-28 15:39:32-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-28 15:39:32-04:00
log901b5c1566a497822b98ba9327578839bac3df50
treea086b61f7e6d4ee6b252c9c1ca037b48d77edee8
parent09cc1dc66067f378a1508e34c0714b659b445724
signaturelock-open Commit is signed but in an unrecognized format.

add compile error for function prototype with no body

closes #1231

2 files changed, 17 insertions(+), 0 deletions(-)

src/analyze.cpp+7
......@@ -3242,6 +3242,13 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
32423242 } else if (tld->id == TldIdFn) {
32433243 assert(tld->source_node->type == NodeTypeFnProto);
32443244 is_export = tld->source_node->data.fn_proto.is_export;
3245
3246 if (!is_export && !tld->source_node->data.fn_proto.is_extern &&
3247 tld->source_node->data.fn_proto.fn_def_node == nullptr)
3248 {
3249 add_node_error(g, tld->source_node, buf_sprintf("non-extern function has no body"));
3250 return;
3251 }
32453252 }
32463253 if (is_export) {
32473254 g->resolve_queue.append(tld);
test/compile_errors.zig+10
......@@ -1,6 +1,16 @@
11const tests = @import("tests.zig");
22
33pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "function protoype with no body",
6 \\fn foo() void;
7 \\export fn entry() void {
8 \\ foo();
9 \\}
10 ,
11 ".tmp_source.zig:1:1: error: non-extern function has no body",
12 );
13
414 cases.add(
515 "@typeInfo causing depend on itself compile error",
616 \\const start = struct {