From 4da820ef61ef6201723448802af85f50e25fd61a Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Thu, 17 Oct 2013 03:39:14 -0400 Subject: [PATCH] Enforce void type on accumulatable functions. --- parser.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/parser.c b/parser.c index 628f89d..2ac19ec 100644 --- 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); -- 2.39.2