authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-04-17 22:02:49+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-04-17 22:02:49+03:00
log1afaf42525760edb78c287c216fda4aafc03d68f
tree1069633e296b5f0e82161cd2458616dd43fac817
parentc026a9f6d254cb4b6cf5d75105f17e3c912e32c2
signaturelock-open Commit is signed but in an unrecognized format.

add error for non-exter variadic functions


3 files changed, 20 insertions(+), 5 deletions(-)

src/analyze.cpp+7-1
......@@ -3619,12 +3619,18 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
36193619 assert(tld->source_node->type == NodeTypeFnProto);
36203620 is_export = tld->source_node->data.fn_proto.is_export;
36213621
3622 if (!is_export && !tld->source_node->data.fn_proto.is_extern &&
3622 if (!tld->source_node->data.fn_proto.is_extern &&
36233623 tld->source_node->data.fn_proto.fn_def_node == nullptr)
36243624 {
36253625 add_node_error(g, tld->source_node, buf_sprintf("non-extern function has no body"));
36263626 return;
36273627 }
3628 if (!tld->source_node->data.fn_proto.is_extern &&
3629 tld->source_node->data.fn_proto.is_var_args)
3630 {
3631 add_node_error(g, tld->source_node, buf_sprintf("non-extern function is variadic"));
3632 return;
3633 }
36283634 } else if (tld->id == TldIdUsingNamespace) {
36293635 g->resolve_queue.append(tld);
36303636 }
src/ir.cpp+1-1
......@@ -25375,7 +25375,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
2537525375 case ZigTypeIdBoundFn:
2537625376 case ZigTypeIdStruct:
2537725377 ir_add_error(ira, source_instr, buf_sprintf(
25378 "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));
25378 "@Type not available for 'TypeInfo.%s'", type_id_name(tagTypeId)));
2537925379 return ira->codegen->invalid_inst_gen->value->type;
2538025380 }
2538125381 zig_unreachable();
test/compile_errors.zig+12-3
......@@ -2,6 +2,15 @@ const tests = @import("tests.zig");
22const std = @import("std");
33
44pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add("non-extern function with var args",
6 \\fn foo(args: ...) void {}
7 \\export fn entry() void {
8 \\ foo();
9 \\}
10 , &[_][]const u8{
11 "tmp.zig:1:1: error: non-extern function is variadic",
12 });
13
514 cases.addTest("invalid int casts",
615 \\export fn foo() void {
716 \\ var a: u32 = 2;
......@@ -856,7 +865,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
856865 "tmp.zig:11:25: error: expected type 'u32', found '@TypeOf(get_uval).ReturnType.ErrorSet!u32'",
857866 });
858867
859 cases.add("asigning to struct or union fields that are not optionals with a function that returns an optional",
868 cases.add("assigning to struct or union fields that are not optionals with a function that returns an optional",
860869 \\fn maybe(is: bool) ?u8 {
861870 \\ if (is) return @as(u8, 10) else return null;
862871 \\}
......@@ -1084,7 +1093,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
10841093 \\ _ = @Type(@typeInfo(struct { }));
10851094 \\}
10861095 , &[_][]const u8{
1087 "tmp.zig:2:15: error: @Type not availble for 'TypeInfo.Struct'",
1096 "tmp.zig:2:15: error: @Type not available for 'TypeInfo.Struct'",
10881097 });
10891098
10901099 cases.add("wrong type for result ptr to @asyncCall",
......@@ -2659,7 +2668,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
26592668 "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter",
26602669 });
26612670
2662 cases.add("function protoype with no body",
2671 cases.add("function prototype with no body",
26632672 \\fn foo() void;
26642673 \\export fn entry() void {
26652674 \\ foo();