From 9c8dc43775285c0056ab539a436b013c7933bc76 Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Wed, 21 Nov 2012 20:56:51 +0100 Subject: [PATCH] error if the ternary operands aren't of the same type - except for the first one of course --- parser.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/parser.c b/parser.c index 525192e..94bcc62 100644 --- a/parser.c +++ b/parser.c @@ -768,6 +768,12 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy) break; case opid2('?',':'): + if (exprs[1]->expression.vtype != exprs[2]->expression.vtype) { + ast_type_to_string(exprs[1], ty1, sizeof(ty1)); + ast_type_to_string(exprs[2], ty2, sizeof(ty2)); + parseerror(parser, "iperands of ternary expression must have the same type, got %s and %s", ty1, ty2); + return false; + } if (CanConstFold1(exprs[0])) out = (ConstF(0) ? exprs[1] : exprs[2]); else -- 2.39.2