zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit cbc4e59e6805d27f0e889c0a9ff8488376cea5c0 (tree)
parent ccca4b5a5e98dd96aaeb365af6c1cfbe87dca181
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Tue, 18 Feb 2020 18:45:25 -0500

Merge branch 'LemonBoy-c8c8c8c8'

closes #4502

Diffstat:
Mdoc/langref.html.in | 2+-
Mlib/std/zig/parser_test.zig | 2++
Mlib/std/zig/render.zig | 1+
Msrc/parser.cpp | 3+++
Mtest/compile_errors.zig | 12++++++++++--
5 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/doc/langref.html.in b/doc/langref.html.in @@ -7399,7 +7399,7 @@ comptime { @export(internalName, .{ .name = "foo", .linkage = .Strong }); } -extern fn internalName() void {} +fn internalName() callconv(.C) void {} {#code_end#} <p>This is equivalent to:</p> {#code_begin|obj#} diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig @@ -92,10 +92,12 @@ test "zig fmt: convert extern/nakedcc/stdcallcc into callconv(...)" { \\nakedcc fn foo1() void {} \\stdcallcc fn foo2() void {} \\extern fn foo3() void {} + \\extern "mylib" fn foo4() void {} , \\fn foo1() callconv(.Naked) void {} \\fn foo2() callconv(.Stdcall) void {} \\fn foo3() callconv(.C) void {} + \\fn foo4() callconv(.C) void {} \\ ); } diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig @@ -1396,6 +1396,7 @@ fn renderExpression( try renderToken(tree, stream, extern_export_inline_token, indent, start_col, Space.Space); // extern/export } else { cc_rewrite_str = ".C"; + fn_proto.lib_name = null; } } diff --git a/src/parser.cpp b/src/parser.cpp @@ -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; diff --git a/test/compile_errors.zig b/test/compile_errors.zig @@ -3,15 +3,23 @@ const builtin = @import("builtin"); const Target = @import("std").Target; pub fn addCases(cases: *tests.CompileErrorContext) void { - cases.addTest("", + cases.addTest("access invalid @typeInfo decl", \\const A = B; \\test "Crash" { - \\ _ = @typeInfo(@This()).Struct.decls; + \\ _ = @typeInfo(@This()).Struct.decls[0]; \\} , &[_][]const u8{ "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 = .{