From 9afe41471bc37964bb933a8e246d8e5c676b2309 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Fri, 25 Jan 2013 19:17:42 +0100 Subject: [PATCH] error when using a type not usable as boolean in a condition, ie an if statement --- parser.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/parser.c b/parser.c index 159c7a8..ac6428a 100644 --- a/parser.c +++ b/parser.c @@ -2205,6 +2205,12 @@ static ast_expression* process_condition(parser_t *parser, ast_expression *cond, ast_unary *unary; ast_expression *prev; + if (cond->expression.vtype == TYPE_VOID || cond->expression.vtype >= TYPE_VARIANT) { + char ty[1024]; + ast_type_to_string(cond, ty, sizeof(ty)); + compile_error(ast_ctx(cond), "invalid type for if() condition: %s", ty); + } + if (OPTS_FLAG(FALSE_EMPTY_STRINGS) && cond->expression.vtype == TYPE_STRING) { prev = cond; -- 2.39.2