]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
Enforce void type on accumulatable functions.
authorDale Weiler <killfieldengine@gmail.com>
Thu, 17 Oct 2013 07:39:14 +0000 (03:39 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Thu, 17 Oct 2013 07:39:14 +0000 (03:39 -0400)
parser.c

index 628f89d691aedefaae09b3ea10fae8cdb7edd502..2ac19ec70dd62e11886a1c6d8017a4b87995ce71 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -3991,11 +3991,21 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
     }
 
     /* accumulation? */
-    if (var->hasvalue) {
+    if (var->hasvalue && var->expression.vtype == TYPE_FUNCTION) {
         ast_value    *accum    = NULL;
         ast_function *previous = NULL;
         char          acname[1024];
 
+        /* only void please */
+        if (var->expression.next->vtype != TYPE_VOID) {
+            parseerror(parser, "accumulated function `%s` declared with return type `%s` (accumulated functions must return void)",
+                var->name,
+                type_name[var->expression.next->vtype]
+            );
+            ast_block_delete(block);
+            goto enderr;
+        }
+
         /* generate a new name increasing the accumulation count*/
         util_snprintf(acname, sizeof(acname), "$ACCUMULATE_%s_%d", var->name, var->constval.vfunc->accumulation++);
         accum = ast_value_new(parser_ctx(parser), acname, ((ast_expression*)var)->vtype);