From: Ben Pfaff Date: Mon, 20 Dec 2021 00:02:01 +0000 (-0800) Subject: improve error messages X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3c96903451307e60d1d4a680ecf58c86cac7eaa;p=pspp improve error messages --- diff --git a/src/language/expressions/parse.c b/src/language/expressions/parse.c index 3b18be72dd..2b78b0b14b 100644 --- a/src/language/expressions/parse.c +++ b/src/language/expressions/parse.c @@ -593,10 +593,7 @@ parse_binary_operators__ (struct lexer *lexer, struct expression *e, return NULL; struct expr_node *node = expr_allocate_binary (e, optype, lhs, rhs); - bool lhs_ok = type_coercion (e, node, 0); - bool rhs_ok = type_coercion (e, node, 1); - - if (!lhs_ok || !rhs_ok) + if (!is_coercible (node, 0) || !is_coercible (node, 1)) { bool both = false; for (size_t i = 0; i < n_ops; i++) @@ -615,15 +612,18 @@ parse_binary_operators__ (struct lexer *lexer, struct expression *e, _("Both operands of %s must be strings."), name); msg_at (SN, expr_location (e, node->args[0]), - _("The left-hand operand of %s has type '%s'."), - name, atom_type_name (expr_node_returns (node->args[0]))); + _("This operand has type '%s'."), + atom_type_name (expr_node_returns (node->args[0]))); msg_at (SN, expr_location (e, node->args[1]), - _("The right-hand operand of %s has type '%s'."), - name, atom_type_name (expr_node_returns (node->args[1]))); + _("This operand has type '%s'."), + atom_type_name (expr_node_returns (node->args[1]))); return NULL; } + if (!type_coercion (e, node, 0) || !type_coercion (e, node, 1)) + NOT_REACHED (); + lhs = node; } } @@ -1400,7 +1400,11 @@ static const char * atom_type_name (atom_type type) { assert (is_atom (type)); - return operations[type].name; + + /* The Boolean type is purely an internal concept that the documentation + doesn't mention, so it might confuse users if we talked about them in + diagnostics. */ + return type == OP_boolean ? "number" : operations[type].name; } struct expr_node *