Module Name: src
Committed By: rillig
Date: Sun Sep 4 22:55:00 UTC 2022
Modified Files:
src/usr.bin/make: cond.c
src/usr.bin/make/unit-tests: cond-cmp-numeric.exp cond-cmp-numeric.mk
cond-cmp-string.exp cond-op-parentheses.exp cond-op-parentheses.mk
varmod-ifelse.exp
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.335 -r1.336 src/usr.bin/make/cond.c
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/cond-cmp-numeric.exp
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/cond-cmp-numeric.mk \
src/usr.bin/make/unit-tests/cond-op-parentheses.mk
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/make/unit-tests/cond-cmp-string.exp
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/cond-op-parentheses.exp
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/varmod-ifelse.exp
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.335 src/usr.bin/make/cond.c:1.336
--- src/usr.bin/make/cond.c:1.335 Fri Sep 2 16:24:31 2022
+++ src/usr.bin/make/cond.c Sun Sep 4 22:55:00 2022
@@ -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 @@ EvalCompareStr(CondParser *par, const ch
{
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;
}
Index: src/usr.bin/make/unit-tests/cond-cmp-numeric.exp
diff -u src/usr.bin/make/unit-tests/cond-cmp-numeric.exp:1.7 src/usr.bin/make/unit-tests/cond-cmp-numeric.exp:1.8
--- src/usr.bin/make/unit-tests/cond-cmp-numeric.exp:1.7 Thu Mar 3 19:36:35 2022
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric.exp Sun Sep 4 22:55:00 2022
@@ -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 @@ make: "cond-cmp-numeric.mk" line 34: Mal
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
Index: src/usr.bin/make/unit-tests/cond-cmp-numeric.mk
diff -u src/usr.bin/make/unit-tests/cond-cmp-numeric.mk:1.5 src/usr.bin/make/unit-tests/cond-cmp-numeric.mk:1.6
--- src/usr.bin/make/unit-tests/cond-cmp-numeric.mk:1.5 Thu Jul 29 06:31:18 2021
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric.mk Sun Sep 4 22:55:00 2022
@@ -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
Index: src/usr.bin/make/unit-tests/cond-op-parentheses.mk
diff -u src/usr.bin/make/unit-tests/cond-op-parentheses.mk:1.5 src/usr.bin/make/unit-tests/cond-op-parentheses.mk:1.6
--- src/usr.bin/make/unit-tests/cond-op-parentheses.mk:1.5 Sat Jan 22 21:50:41 2022
+++ src/usr.bin/make/unit-tests/cond-op-parentheses.mk Sun Sep 4 22:55:00 2022
@@ -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)
Index: src/usr.bin/make/unit-tests/cond-cmp-string.exp
diff -u src/usr.bin/make/unit-tests/cond-cmp-string.exp:1.11 src/usr.bin/make/unit-tests/cond-cmp-string.exp:1.12
--- src/usr.bin/make/unit-tests/cond-cmp-string.exp:1.11 Thu Jan 21 23:32:28 2021
+++ src/usr.bin/make/unit-tests/cond-cmp-string.exp Sun Sep 4 22:55:00 2022
@@ -2,10 +2,10 @@ make: "cond-cmp-string.mk" line 18: Malf
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
Index: src/usr.bin/make/unit-tests/cond-op-parentheses.exp
diff -u src/usr.bin/make/unit-tests/cond-op-parentheses.exp:1.4 src/usr.bin/make/unit-tests/cond-op-parentheses.exp:1.5
--- src/usr.bin/make/unit-tests/cond-op-parentheses.exp:1.4 Sat Jan 22 21:50:41 2022
+++ src/usr.bin/make/unit-tests/cond-op-parentheses.exp Sun Sep 4 22:55:00 2022
@@ -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
Index: src/usr.bin/make/unit-tests/varmod-ifelse.exp
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.12 src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.13
--- src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.12 Thu Mar 3 19:36:35 2022
+++ src/usr.bin/make/unit-tests/varmod-ifelse.exp Sun Sep 4 22:55:00 2022
@@ -16,7 +16,7 @@ CondParser_Eval: ${VAR} == value
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'