bugfix for variadic arguments
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 7 Sep 2020 21:52:40 +0000 (16:52 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 7 Sep 2020 21:52:40 +0000 (16:52 -0500)
onyx
src/onyxchecker.c

diff --git a/onyx b/onyx
index ada98626987eb83be0ece26aae9627ae53bb3fc0..ff1a0ff8ae1d724d2b2b21712a671a6750f46687 100755 (executable)
Binary files a/onyx and b/onyx differ
index 7815d03827c93883ed5cbce193885ad2e0609edb..32a92b3e89da1a727397f790f2a58e7b5fc6d990 100644 (file)
@@ -462,6 +462,7 @@ b32 check_call(AstCall* call) {
     actual = call->arguments;
 
     Type* variadic_type = NULL;
+    AstParam* variadic_param = NULL;
 
     i32 arg_pos = 0;
     while (1) {
@@ -470,6 +471,7 @@ b32 check_call(AstCall* call) {
 
         if (variadic_type == NULL && formal_params[arg_pos]->kind == Type_Kind_VarArgs) {
             variadic_type = formal_params[arg_pos]->VarArgs.ptr_to_data->Pointer.elem;
+            variadic_param = &callee->params[arg_pos];
         }
 
         if (variadic_type != NULL) {
@@ -477,9 +479,9 @@ b32 check_call(AstCall* call) {
                 onyx_report_error(actual->token->pos,
                         "The function '%b' expects a value of type '%s' for the variadic parameter, '%b', got '%s'.",
                         callee->token->text, callee->token->length,
-                        type_get_name(formal_params[arg_pos]),
-                        callee->params[arg_pos].local->token->text,
-                        callee->params[arg_pos].local->token->length,
+                        type_get_name(variadic_type),
+                        variadic_param->local->token->text,
+                        variadic_param->local->token->length,
                         type_get_name(actual->type));
                 return 1;
             }