Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make: add more details to error message for num...



details:   https://anonhg.NetBSD.org/src/rev/d1c9359644aa
branches:  trunk
changeset: 369867:d1c9359644aa
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Sep 04 22:55:00 2022 +0000

description:
make: add more details to error message for numeric comparison

Before:
String comparison operator must be either == or !=

After:
Comparison with '>=' requires both operands 'no' and '10' to be numeric

Noticed by martin@ in pkgsrc/textproc/py-pygments.

diffstat:

 usr.bin/make/cond.c                             |  8 +++++---
 usr.bin/make/unit-tests/cond-cmp-numeric.exp    |  6 +++---
 usr.bin/make/unit-tests/cond-cmp-numeric.mk     |  4 ++--
 usr.bin/make/unit-tests/cond-cmp-string.exp     |  8 ++++----
 usr.bin/make/unit-tests/cond-op-parentheses.exp |  8 ++++----
 usr.bin/make/unit-tests/cond-op-parentheses.mk  |  7 +++++--
 usr.bin/make/unit-tests/varmod-ifelse.exp       |  2 +-
 7 files changed, 24 insertions(+), 19 deletions(-)

diffs (135 lines):

diff -r 3814123baad1 -r d1c9359644aa usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sun Sep 04 22:34:58 2022 +0000
+++ b/usr.bin/make/cond.c       Sun Sep 04 22:55:00 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.335 2022/09/02 16:24:31 sjg Exp $   */
+/*     $NetBSD: cond.c,v 1.336 2022/09/04 22:55:00 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.335 2022/09/02 16:24:31 sjg Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.336 2022/09/04 22:55:00 rillig Exp $");
 
 /*
  * Conditional expressions conform to this grammar:
@@ -583,7 +583,9 @@
 {
        if (op != EQ && op != NE) {
                Parse_Error(PARSE_FATAL,
-                   "String comparison operator must be either == or !=");
+                   "Comparison with '%s' requires both operands "
+                   "'%s' and '%s' to be numeric",
+                   opname[op], lhs, rhs);
                par->printedError = true;
                return TOK_ERROR;
        }
diff -r 3814123baad1 -r d1c9359644aa usr.bin/make/unit-tests/cond-cmp-numeric.exp
--- a/usr.bin/make/unit-tests/cond-cmp-numeric.exp      Sun Sep 04 22:34:58 2022 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-numeric.exp      Sun Sep 04 22:55:00 2022 +0000
@@ -1,7 +1,7 @@
 CondParser_Eval: !(${:UINF} > 1e100)
-make: "cond-cmp-numeric.mk" line 11: String comparison operator must be either == or !=
+make: "cond-cmp-numeric.mk" line 11: Comparison with '>' requires both operands 'INF' and '1e100' to be numeric
 CondParser_Eval: ${:UNaN} > NaN
-make: "cond-cmp-numeric.mk" line 16: String comparison operator must be either == or !=
+make: "cond-cmp-numeric.mk" line 16: Comparison with '>' requires both operands 'NaN' and 'NaN' to be numeric
 CondParser_Eval: !(${:UNaN} == NaN)
 Comparing "NaN" == "NaN"
 CondParser_Eval: 123 ! 123
@@ -9,7 +9,7 @@
 CondParser_Eval: ${:U 123} < 124
 Comparing 123.000000 < 124.000000
 CondParser_Eval: ${:U123 } < 124
-make: "cond-cmp-numeric.mk" line 50: String comparison operator must be either == or !=
+make: "cond-cmp-numeric.mk" line 50: Comparison with '<' requires both operands '123 ' and '124' to be numeric
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 3814123baad1 -r d1c9359644aa usr.bin/make/unit-tests/cond-cmp-numeric.mk
--- a/usr.bin/make/unit-tests/cond-cmp-numeric.mk       Sun Sep 04 22:34:58 2022 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-numeric.mk       Sun Sep 04 22:55:00 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: cond-cmp-numeric.mk,v 1.5 2021/07/29 06:31:18 rillig Exp $
+# $NetBSD: cond-cmp-numeric.mk,v 1.6 2022/09/04 22:55:00 rillig Exp $
 #
 # Tests for numeric comparisons in .if conditions.
 
@@ -46,7 +46,7 @@
 
 # Trailing spaces are NOT allowed for numbers.
 # See EvalCompare and TryParseNumber.
-# expect+1: String comparison operator must be either == or !=
+# expect+1: Comparison with '<' requires both operands '123 ' and '124' to be numeric
 .if ${:U123 } < 124
 .  error
 .else
diff -r 3814123baad1 -r d1c9359644aa usr.bin/make/unit-tests/cond-cmp-string.exp
--- a/usr.bin/make/unit-tests/cond-cmp-string.exp       Sun Sep 04 22:34:58 2022 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-string.exp       Sun Sep 04 22:55:00 2022 +0000
@@ -2,10 +2,10 @@
 make: "cond-cmp-string.mk" line 42: Malformed conditional ("string" != "str""ing")
 make: "cond-cmp-string.mk" line 49: Malformed conditional (!("value" = "value"))
 make: "cond-cmp-string.mk" line 56: Malformed conditional (!("value" === "value"))
-make: "cond-cmp-string.mk" line 113: String comparison operator must be either == or !=
-make: "cond-cmp-string.mk" line 120: String comparison operator must be either == or !=
-make: "cond-cmp-string.mk" line 127: String comparison operator must be either == or !=
-make: "cond-cmp-string.mk" line 134: String comparison operator must be either == or !=
+make: "cond-cmp-string.mk" line 113: Comparison with '<' requires both operands 'string' and 'string' to be numeric
+make: "cond-cmp-string.mk" line 120: Comparison with '<=' requires both operands 'string' and 'string' to be numeric
+make: "cond-cmp-string.mk" line 127: Comparison with '>' requires both operands 'string' and 'string' to be numeric
+make: "cond-cmp-string.mk" line 134: Comparison with '>=' requires both operands 'string' and 'string' to be numeric
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 3814123baad1 -r d1c9359644aa usr.bin/make/unit-tests/cond-op-parentheses.exp
--- a/usr.bin/make/unit-tests/cond-op-parentheses.exp   Sun Sep 04 22:34:58 2022 +0000
+++ b/usr.bin/make/unit-tests/cond-op-parentheses.exp   Sun Sep 04 22:55:00 2022 +0000
@@ -1,7 +1,7 @@
-make: "cond-op-parentheses.mk" line 19: String comparison operator must be either == or !=
-make: "cond-op-parentheses.mk" line 22: Malformed conditional ((3) > 2)
-make: "cond-op-parentheses.mk" line 40: Malformed conditional (()
-make: "cond-op-parentheses.mk" line 53: Malformed conditional ())
+make: "cond-op-parentheses.mk" line 22: Comparison with '>' requires both operands '3' and '(2' to be numeric
+make: "cond-op-parentheses.mk" line 25: Malformed conditional ((3) > 2)
+make: "cond-op-parentheses.mk" line 43: Malformed conditional (()
+make: "cond-op-parentheses.mk" line 56: Malformed conditional ())
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 3814123baad1 -r d1c9359644aa usr.bin/make/unit-tests/cond-op-parentheses.mk
--- a/usr.bin/make/unit-tests/cond-op-parentheses.mk    Sun Sep 04 22:34:58 2022 +0000
+++ b/usr.bin/make/unit-tests/cond-op-parentheses.mk    Sun Sep 04 22:55:00 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op-parentheses.mk,v 1.5 2022/01/22 21:50:41 rillig Exp $
+# $NetBSD: cond-op-parentheses.mk,v 1.6 2022/09/04 22:55:00 rillig Exp $
 #
 # Tests for parentheses in .if conditions, which group expressions to override
 # the precedence of the operators '!', '&&' and '||'.  Parentheses cannot be
@@ -15,7 +15,10 @@
 # Parentheses cannot enclose numbers as there is no need for it.  Make does
 # not implement any arithmetic functions in its condition parser.  If
 # absolutely necessary, use expr(1).
-# expect+1: String comparison operator must be either == or !=
+#
+# XXX: It's inconsistent that the right operand has unbalanced parentheses.
+#
+# expect+1: Comparison with '>' requires both operands '3' and '(2' to be numeric
 .if 3 > (2)
 .endif
 # expect+1: Malformed conditional ((3) > 2)
diff -r 3814123baad1 -r d1c9359644aa usr.bin/make/unit-tests/varmod-ifelse.exp
--- a/usr.bin/make/unit-tests/varmod-ifelse.exp Sun Sep 04 22:34:58 2022 +0000
+++ b/usr.bin/make/unit-tests/varmod-ifelse.exp Sun Sep 04 22:55:00 2022 +0000
@@ -16,7 +16,7 @@
 Comparing "value" == "value"
 Comparing "ok" != "ok"
 make: "varmod-ifelse.mk" line 153: no.
-make: "varmod-ifelse.mk" line 154: String comparison operator must be either == or !=
+make: "varmod-ifelse.mk" line 154: Comparison with '>=' requires both operands 'no' and '10' to be numeric
 make: Bad conditional expression 'string == "literal" || no >= 10' in 'string == "literal" || no >= 10?yes:no'
 make: "varmod-ifelse.mk" line 154: .
 make: Bad conditional expression 'string == "literal" &&  >= 10' in 'string == "literal" &&  >= 10?yes:no'



Home | Main Index | Thread Index | Old Index