mirror of
https://github.com/ziglang/zig.git
synced 2026-02-18 07:18:38 +00:00
stage1: Make the parser reject extern fn with body
This commit is contained in:
parent
95a71e29f8
commit
a6b74cdd38
@ -689,6 +689,9 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, B
|
||||
|
||||
AstNode *res = fn_proto;
|
||||
if (body != nullptr) {
|
||||
if (fn_proto->data.fn_proto.is_extern) {
|
||||
ast_error(pc, first, "Extern functions have no body");
|
||||
}
|
||||
res = ast_create_node_copy_line_info(pc, NodeTypeFnDef, fn_proto);
|
||||
res->data.fn_def.fn_proto = fn_proto;
|
||||
res->data.fn_def.body = body;
|
||||
|
||||
@ -12,6 +12,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
"tmp.zig:1:11: error: use of undeclared identifier 'B'",
|
||||
});
|
||||
|
||||
cases.addTest("reject extern function definitions with body",
|
||||
\\extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 {
|
||||
\\ return a + b;
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:1:1: error: Extern functions have no body",
|
||||
});
|
||||
|
||||
cases.addTest("duplicate field in anonymous struct literal",
|
||||
\\export fn entry() void {
|
||||
\\ const anon = .{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user