From 5aba29006bdd32442ee2ed3e4c9c6eaf911a806b Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 29 May 2013 16:58:18 +0200 Subject: [PATCH] return assignment factorial test --- parser.c | 5 +++++ tests/rassign.qc | 10 +++++++++- tests/rassign.tmpl | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/parser.c b/parser.c index 27c694d..d9be036 100644 --- a/parser.c +++ b/parser.c @@ -2955,6 +2955,11 @@ static bool parse_return(parser_t *parser, ast_block *block, ast_expression **ou return false; } + if (parser->tok != ';') + parseerror(parser, "missing semicolon after return assignment"); + else if (!parser_next(parser)) + parseerror(parser, "parse error after return assignment"); + *out = var; return true; } diff --git a/tests/rassign.qc b/tests/rassign.qc index 7e3d0e6..69ec31c 100644 --- a/tests/rassign.qc +++ b/tests/rassign.qc @@ -9,7 +9,7 @@ vector f_vector() { foo.x = f_float(); foo.y = f_float(); foo.z = f_float(); - + return = foo; return; } @@ -20,8 +20,16 @@ string f_string() { return; } +float factorial(float n) { + if (n == 0) return = 1; + else return = n * factorial(n - 1); + + return; +} + void main() { print(ftos(f_float()), "\n"); // 200.0f print(vtos(f_vector()), "\n"); // '1 2 3' print(f_string(), "\n"); // world + print(ftos(factorial(4)), "\n"); // 24 } diff --git a/tests/rassign.tmpl b/tests/rassign.tmpl index 63642aa..f169c82 100644 --- a/tests/rassign.tmpl +++ b/tests/rassign.tmpl @@ -5,3 +5,4 @@ C: -freturn-assignments M: 200 M: '200 200 200' M: world +M: 24