authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-02-18 22:53:03+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-18 18:18:29-05:00
loga6b74cdd38a2aac25275c97c00133ec7134aacd2
tree2eaf781005ce814d8d243326d41b6134982e83ac
parent95a71e29f84573ce72b16406eaf1a6dff96de35f
signaturelock-open Commit is signed but in an unrecognized format.

stage1: Make the parser reject extern fn with body


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

src/parser.cpp+3
......@@ -689,6 +689,9 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, B
689689
690690 AstNode *res = fn_proto;
691691 if (body != nullptr) {
692 if (fn_proto->data.fn_proto.is_extern) {
693 ast_error(pc, first, "Extern functions have no body");
694 }
692695 res = ast_create_node_copy_line_info(pc, NodeTypeFnDef, fn_proto);
693696 res->data.fn_def.fn_proto = fn_proto;
694697 res->data.fn_def.body = body;
test/compile_errors.zig+8
......@@ -12,6 +12,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1212 "tmp.zig:1:11: error: use of undeclared identifier 'B'",
1313 });
1414
15 cases.addTest("reject extern function definitions with body",
16 \\extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 {
17 \\ return a + b;
18 \\}
19 , &[_][]const u8{
20 "tmp.zig:1:1: error: Extern functions have no body",
21 });
22
1523 cases.addTest("duplicate field in anonymous struct literal",
1624 \\export fn entry() void {
1725 \\ const anon = .{