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) {...@@ -3619,12 +3619,18 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
3619 assert(tld->source_node->type == NodeTypeFnProto);3619 assert(tld->source_node->type == NodeTypeFnProto);
3620 is_export = tld->source_node->data.fn_proto.is_export;3620 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 &&
3623 tld->source_node->data.fn_proto.fn_def_node == nullptr)3623 tld->source_node->data.fn_proto.fn_def_node == nullptr)
3624 {3624 {
3625 add_node_error(g, tld->source_node, buf_sprintf("non-extern function has no body"));3625 add_node_error(g, tld->source_node, buf_sprintf("non-extern function has no body"));
3626 return;3626 return;
3627 }3627 }
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 }
3628 } else if (tld->id == TldIdUsingNamespace) {3634 } else if (tld->id == TldIdUsingNamespace) {
3629 g->resolve_queue.append(tld);3635 g->resolve_queue.append(tld);
3630 }3636 }
src/ir.cpp+1-1
...@@ -25375,7 +25375,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -25375,7 +25375,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
25375 case ZigTypeIdBoundFn:25375 case ZigTypeIdBoundFn:
25376 case ZigTypeIdStruct:25376 case ZigTypeIdStruct:
25377 ir_add_error(ira, source_instr, buf_sprintf(25377 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)));
25379 return ira->codegen->invalid_inst_gen->value->type;25379 return ira->codegen->invalid_inst_gen->value->type;
25380 }25380 }
25381 zig_unreachable();25381 zig_unreachable();
test/compile_errors.zig+12-3
...@@ -2,6 +2,15 @@ const tests = @import("tests.zig");...@@ -2,6 +2,15 @@ const tests = @import("tests.zig");
2const std = @import("std");2const std = @import("std");
33
4pub fn addCases(cases: *tests.CompileErrorContext) void {4pub 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
5 cases.addTest("invalid int casts",14 cases.addTest("invalid int casts",
6 \\export fn foo() void {15 \\export fn foo() void {
7 \\ var a: u32 = 2;16 \\ var a: u32 = 2;
...@@ -856,7 +865,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -856,7 +865,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
856 "tmp.zig:11:25: error: expected type 'u32', found '@TypeOf(get_uval).ReturnType.ErrorSet!u32'",865 "tmp.zig:11:25: error: expected type 'u32', found '@TypeOf(get_uval).ReturnType.ErrorSet!u32'",
857 });866 });
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",
860 \\fn maybe(is: bool) ?u8 {869 \\fn maybe(is: bool) ?u8 {
861 \\ if (is) return @as(u8, 10) else return null;870 \\ if (is) return @as(u8, 10) else return null;
862 \\}871 \\}
...@@ -1084,7 +1093,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1084,7 +1093,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1084 \\ _ = @Type(@typeInfo(struct { }));1093 \\ _ = @Type(@typeInfo(struct { }));
1085 \\}1094 \\}
1086 , &[_][]const u8{1095 , &[_][]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'",
1088 });1097 });
10891098
1090 cases.add("wrong type for result ptr to @asyncCall",1099 cases.add("wrong type for result ptr to @asyncCall",
...@@ -2659,7 +2668,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2659,7 +2668,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2659 "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter",2668 "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter",
2660 });2669 });
26612670
2662 cases.add("function protoype with no body",2671 cases.add("function prototype with no body",
2663 \\fn foo() void;2672 \\fn foo() void;
2664 \\export fn entry() void {2673 \\export fn entry() void {
2665 \\ foo();2674 \\ foo();