| author | |
| committer | |
| log | a6b74cdd38a2aac25275c97c00133ec7134aacd2 |
| tree | 2eaf781005ce814d8d243326d41b6134982e83ac |
| parent | 95a71e29f84573ce72b16406eaf1a6dff96de35f |
| signature | Commit is signed but in an unrecognized format. |
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 | ... | @@ -689,6 +689,9 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, B |
| 689 | 689 | ||
| 690 | AstNode *res = fn_proto; | 690 | AstNode *res = fn_proto; |
| 691 | if (body != nullptr) { | 691 | if (body != nullptr) { |
| 692 | if (fn_proto->data.fn_proto.is_extern) { | ||
| 693 | ast_error(pc, first, "Extern functions have no body"); | ||
| 694 | } | ||
| 692 | res = ast_create_node_copy_line_info(pc, NodeTypeFnDef, fn_proto); | 695 | res = ast_create_node_copy_line_info(pc, NodeTypeFnDef, fn_proto); |
| 693 | res->data.fn_def.fn_proto = fn_proto; | 696 | res->data.fn_def.fn_proto = fn_proto; |
| 694 | res->data.fn_def.body = body; | 697 | res->data.fn_def.body = body; |
test/compile_errors.zig+8| ... | @@ -12,6 +12,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -12,6 +12,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 12 | "tmp.zig:1:11: error: use of undeclared identifier 'B'", | 12 | "tmp.zig:1:11: error: use of undeclared identifier 'B'", |
| 13 | }); | 13 | }); |
| 14 | 14 | ||
| 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 | |||
| 15 | cases.addTest("duplicate field in anonymous struct literal", | 23 | cases.addTest("duplicate field in anonymous struct literal", |
| 16 | \\export fn entry() void { | 24 | \\export fn entry() void { |
| 17 | \\ const anon = .{ | 25 | \\ const anon = .{ |