From: Ben Pfaff Date: Sun, 6 Jun 2010 19:19:19 +0000 (-0700) Subject: expressions: Improve error messages evaluating invalid Boolean values. X-Git-Tag: v0.7.6~379 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=263613c4fe117bcf0702cc7d0d334068b2424d37;p=pspp-builds.git expressions: Improve error messages evaluating invalid Boolean values. The error message used for an invalid Boolean value was terribly generic. This commit adds the name of the operator to the error message. --- diff --git a/src/language/expressions/operations.def b/src/language/expressions/operations.def index d2838672..d3044043 100644 --- a/src/language/expressions/operations.def +++ b/src/language/expressions/operations.def @@ -630,16 +630,16 @@ absorb_miss no_opt no_abbrev string function VALUELABEL (var v) // Artificial. operator SQUARE (x) = x * x; -boolean operator NUM_TO_BOOLEAN (x) +boolean operator NUM_TO_BOOLEAN (x, string op_name) { if (x == 0. || x == 1. || x == SYSMIS) return x; else { - msg (SE, _("A number being treated as a Boolean in an " - "expression was found to have a value other than " - "0 (false), 1 (true), or the system-missing value. " - "The result was forced to 0.")); + msg (SE, _("An operand of the %.*s operator was found to have a value " + "other than 0 (false), 1 (true), or the system-missing " + "value. The result was forced to 0."), + (int) op_name.length, op_name.string); return 0.; } } diff --git a/src/language/expressions/parse.c b/src/language/expressions/parse.c index 3577443d..ca510852 100644 --- a/src/language/expressions/parse.c +++ b/src/language/expressions/parse.c @@ -344,7 +344,13 @@ type_coercion_core (struct expression *e, { /* Convert numeric to boolean. */ if (do_coercion) - *node = expr_allocate_unary (e, OP_NUM_TO_BOOLEAN, *node); + { + union any_node *op_name; + + op_name = expr_allocate_string (e, ss_cstr (operator_name)); + *node = expr_allocate_binary (e, OP_NUM_TO_BOOLEAN, *node, + op_name); + } return true; } break;