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) {...@@ -3242,6 +3242,13 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
3242 } else if (tld->id == TldIdFn) {3242 } else if (tld->id == TldIdFn) {
3243 assert(tld->source_node->type == NodeTypeFnProto);3243 assert(tld->source_node->type == NodeTypeFnProto);
3244 is_export = tld->source_node->data.fn_proto.is_export;3244 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 }
3245 }3252 }
3246 if (is_export) {3253 if (is_export) {
3247 g->resolve_queue.append(tld);3254 g->resolve_queue.append(tld);
test/compile_errors.zig+10
...@@ -1,6 +1,16 @@...@@ -1,6 +1,16 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompileErrorContext) void {3pub 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
4 cases.add(14 cases.add(
5 "@typeInfo causing depend on itself compile error",15 "@typeInfo causing depend on itself compile error",
6 \\const start = struct {16 \\const start = struct {