]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
type restricted varargs
authorWolfgang Bumiller <blub@speed.at>
Sat, 12 Jan 2013 10:10:29 +0000 (11:10 +0100)
committerWolfgang Bumiller <blub@speed.at>
Sat, 12 Jan 2013 10:10:29 +0000 (11:10 +0100)
ast.c

diff --git a/ast.c b/ast.c
index ee41347f97b1fef73eb45c9387a4d1569f12c2ed..f42a65493ed4e0f1ca3543d9965d19029d826352 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -914,6 +914,8 @@ void ast_call_delete(ast_call *self)
 
 bool ast_call_check_types(ast_call *self)
 {
+    char texp[1024];
+    char tgot[1024];
     size_t i;
     bool   retval = true;
     const  ast_expression *func = self->func;
@@ -924,8 +926,6 @@ bool ast_call_check_types(ast_call *self)
     for (i = 0; i < count; ++i) {
         if (!ast_compare_type(self->params[i], (ast_expression*)(func->expression.params[i])))
         {
-            char texp[1024];
-            char tgot[1024];
             ast_type_to_string(self->params[i], tgot, sizeof(tgot));
             ast_type_to_string((ast_expression*)func->expression.params[i], texp, sizeof(texp));
             compile_error(ast_ctx(self), "invalid type for parameter %u in function call: expected %s, got %s",
@@ -934,6 +934,20 @@ bool ast_call_check_types(ast_call *self)
             retval = false;
         }
     }
+    count = vec_size(self->params);
+    if (count > vec_size(func->expression.params) && func->expression.varparam) {
+        for (; i < count; ++i) {
+            if (!ast_compare_type(self->params[i], func->expression.varparam))
+            {
+                ast_type_to_string(self->params[i], tgot, sizeof(tgot));
+                ast_type_to_string(func->expression.varparam, texp, sizeof(texp));
+                compile_error(ast_ctx(self), "invalid type for parameter %u in function call: expected %s, got %s",
+                         (unsigned int)(i+1), texp, tgot);
+                /* we don't immediately return */
+                retval = false;
+            }
+        }
+    }
     return retval;
 }