From 00b0adb52397d9b12297f8c2b7c7253cecf7a053 Mon Sep 17 00:00:00 2001 From: gambas Date: Wed, 28 Feb 2018 14:07:24 +0100 Subject: [PATCH] Don't raise an error when analyzing the AND, OR or XOR operator. Print a warning instead. [COMPILER] * NEW: Don't raise an error when analyzing the AND, OR or XOR operator. * NEW: Print a warning if the AND, OR or XOR operator mix Boolean and Integer datatypes. --- main/gbc/gbc_trans_expr.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/main/gbc/gbc_trans_expr.c b/main/gbc/gbc_trans_expr.c index 04dd31060..d254dbe0d 100644 --- a/main/gbc/gbc_trans_expr.c +++ b/main/gbc/gbc_trans_expr.c @@ -410,6 +410,7 @@ static void trans_operation(short op, short nparam, PATTERN previous) { COMP_INFO *info = &COMP_res_info[op]; int type = info->type; + int type1, type2; switch (info->value) { @@ -484,14 +485,25 @@ static void trans_operation(short op, short nparam, PATTERN previous) break; case RST_AND: - type = Max(get_type(0, nparam), get_type(1, nparam)); - if (type > T_LONG && type != T_VARIANT) // && type != T_STRING) Why ? - THROW("Integer expected"); + type1 = get_type(0, nparam); + type2 = get_type(1, nparam); + + if ((type1 > T_BOOLEAN && type1 <= T_LONG) ^ (type2 > T_BOOLEAN && type2 <= T_LONG)) + COMPILE_print(MSG_WARNING, JOB->line, "integer and boolean mixed with `&1' operator", info->name); + + type = Max(type1, type2); + + if (type > T_LONG) + { + if (type != T_VARIANT) + type = T_BOOLEAN; + } + break; case RST_NOT: type = get_type(0, nparam); - if (type == T_STRING || type == T_OBJECT) + if (type == T_STRING || type == T_OBJECT || type == T_DATE) type = T_BOOLEAN; break; }