aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorD. Bohdan <dbohdan@dbohdan.com>2020-09-27 07:19:08 +0000
committerSteve Bennett <steveb@workware.net.au>2020-09-27 19:25:28 +1000
commit84cf3d13ada8629693c5e8508b1323f5b379cfce (patch)
tree39857f63d351890e33640ddf0797e567fb16f8cc
parent4fc268defe0738c471fea6de5b33d6e356aa7082 (diff)
downloadjimtcl-84cf3d13ada8629693c5e8508b1323f5b379cfce.zip
jimtcl-84cf3d13ada8629693c5e8508b1323f5b379cfce.tar.gz
jimtcl-84cf3d13ada8629693c5e8508b1323f5b379cfce.tar.bz2
core: make unary "!" work with non-int booleans
-rw-r--r--jim.c11
-rw-r--r--tests/expr.test8
2 files changed, 18 insertions, 1 deletions
diff --git a/jim.c b/jim.c
index f676dee..eef1293 100644
--- a/jim.c
+++ b/jim.c
@@ -8056,7 +8056,7 @@ static int JimExprEvalTermNode(Jim_Interp *interp, struct JimExprNode *node);
static int JimExprOpNumUnary(Jim_Interp *interp, struct JimExprNode *node)
{
int intresult = 1;
- int rc;
+ int rc, bA = 0;
double dA, dC = 0;
jim_wide wA, wC = 0;
Jim_Obj *A;
@@ -8123,6 +8123,15 @@ static int JimExprOpNumUnary(Jim_Interp *interp, struct JimExprNode *node)
abort();
}
}
+ else if ((rc = Jim_GetBoolean(interp, A, &bA)) == JIM_OK) {
+ switch (node->type) {
+ case JIM_EXPROP_NOT:
+ wC = !bA;
+ break;
+ default:
+ abort();
+ }
+ }
if (rc == JIM_OK) {
if (intresult) {
diff --git a/tests/expr.test b/tests/expr.test
index b195d4a..d73ddbc 100644
--- a/tests/expr.test
+++ b/tests/expr.test
@@ -142,4 +142,12 @@ test expr-4.1 "Shimmering" {
set a
} {2}
+test expr-5.1 "Not" {
+ lmap x {1 0 true false on off yes no} { expr {!$x} }
+} {0 1 0 1 0 1 0 1}
+
+test expr-5.2 "Not" -body {
+ expr {!this}
+} -returnCodes error -result {syntax error in expression: "!this"}
+
testreport