add error for non-exter variadic functions
parent
c026a9f6d2
commit
1afaf42525
|
@ -3619,12 +3619,18 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
|
|||
assert(tld->source_node->type == NodeTypeFnProto);
|
||||
is_export = tld->source_node->data.fn_proto.is_export;
|
||||
|
||||
if (!is_export && !tld->source_node->data.fn_proto.is_extern &&
|
||||
if (!tld->source_node->data.fn_proto.is_extern &&
|
||||
tld->source_node->data.fn_proto.fn_def_node == nullptr)
|
||||
{
|
||||
add_node_error(g, tld->source_node, buf_sprintf("non-extern function has no body"));
|
||||
return;
|
||||
}
|
||||
if (!tld->source_node->data.fn_proto.is_extern &&
|
||||
tld->source_node->data.fn_proto.is_var_args)
|
||||
{
|
||||
add_node_error(g, tld->source_node, buf_sprintf("non-extern function is variadic"));
|
||||
return;
|
||||
}
|
||||
} else if (tld->id == TldIdUsingNamespace) {
|
||||
g->resolve_queue.append(tld);
|
||||
}
|
||||
|
|
|
@ -25375,7 +25375,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
|
|||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdStruct:
|
||||
ir_add_error(ira, source_instr, buf_sprintf(
|
||||
"@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));
|
||||
"@Type not available for 'TypeInfo.%s'", type_id_name(tagTypeId)));
|
||||
return ira->codegen->invalid_inst_gen->value->type;
|
||||
}
|
||||
zig_unreachable();
|
||||
|
|
|
@ -2,6 +2,15 @@ const tests = @import("tests.zig");
|
|||
const std = @import("std");
|
||||
|
||||
pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
cases.add("non-extern function with var args",
|
||||
\\fn foo(args: ...) void {}
|
||||
\\export fn entry() void {
|
||||
\\ foo();
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:1:1: error: non-extern function is variadic",
|
||||
});
|
||||
|
||||
cases.addTest("invalid int casts",
|
||||
\\export fn foo() void {
|
||||
\\ var a: u32 = 2;
|
||||
|
@ -856,7 +865,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
|||
"tmp.zig:11:25: error: expected type 'u32', found '@TypeOf(get_uval).ReturnType.ErrorSet!u32'",
|
||||
});
|
||||
|
||||
cases.add("asigning to struct or union fields that are not optionals with a function that returns an optional",
|
||||
cases.add("assigning to struct or union fields that are not optionals with a function that returns an optional",
|
||||
\\fn maybe(is: bool) ?u8 {
|
||||
\\ if (is) return @as(u8, 10) else return null;
|
||||
\\}
|
||||
|
@ -1084,7 +1093,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
|||
\\ _ = @Type(@typeInfo(struct { }));
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:2:15: error: @Type not availble for 'TypeInfo.Struct'",
|
||||
"tmp.zig:2:15: error: @Type not available for 'TypeInfo.Struct'",
|
||||
});
|
||||
|
||||
cases.add("wrong type for result ptr to @asyncCall",
|
||||
|
@ -2659,7 +2668,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
|||
"tmp.zig:7:17: error: switch on type 'type' provides no expression parameter",
|
||||
});
|
||||
|
||||
cases.add("function protoype with no body",
|
||||
cases.add("function prototype with no body",
|
||||
\\fn foo() void;
|
||||
\\export fn entry() void {
|
||||
\\ foo();
|
||||
|
|
Loading…
Reference in New Issue