| author | |
| committer | |
| log | 7ea669e04c9314f17ce296c7521ffec2ff8575e9 |
| tree | 4e272dd83789bc4f24506f960c6e0486d6ce6cfa |
| parent | 4f8c26d2c605f24cdeb1a4c7154662b2552640ef |
closes #6012 files changed, 18 insertions(+), 1 deletions(-)
src/ir.cpp+10-1| ... | ... | @@ -10311,8 +10311,17 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 10311 | 10311 | { |
| 10312 | 10312 | FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; |
| 10313 | 10313 | size_t first_arg_1_or_0 = first_arg_ptr ? 1 : 0; |
| 10314 | size_t var_args_1_or_0 = fn_type_id->is_var_args ? 1 : 0; | |
| 10314 | ||
| 10315 | // for extern functions, the var args argument is not counted. | |
| 10316 | // for zig functions, it is. | |
| 10317 | size_t var_args_1_or_0; | |
| 10318 | if (fn_type_id->cc == CallingConventionUnspecified) { | |
| 10319 | var_args_1_or_0 = fn_type_id->is_var_args ? 1 : 0; | |
| 10320 | } else { | |
| 10321 | var_args_1_or_0 = 0; | |
| 10322 | } | |
| 10315 | 10323 | size_t src_param_count = fn_type_id->param_count - var_args_1_or_0; |
| 10324 | ||
| 10316 | 10325 | size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0; |
| 10317 | 10326 | AstNode *source_node = call_instruction->base.source_node; |
| 10318 | 10327 |
test/compile_errors.zig+8| ... | ... | @@ -2335,4 +2335,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2335 | 2335 | \\const Foo = enum {}; |
| 2336 | 2336 | , |
| 2337 | 2337 | ".tmp_source.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members"); |
| 2338 | ||
| 2339 | cases.add("calling var args extern function, passing array instead of pointer", | |
| 2340 | \\export fn entry() { | |
| 2341 | \\ foo("hello"); | |
| 2342 | \\} | |
| 2343 | \\pub extern fn foo(format: &const u8, ...); | |
| 2344 | , | |
| 2345 | ".tmp_source.zig:2:9: error: expected type '&const u8', found '[5]u8'"); | |
| 2338 | 2346 | } |