From 84cf3d13ada8629693c5e8508b1323f5b379cfce Mon Sep 17 00:00:00 2001 From: "D. Bohdan" Date: Sun, 27 Sep 2020 07:19:08 +0000 Subject: core: make unary "!" work with non-int booleans --- jim.c | 11 ++++++++++- tests/expr.test | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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 -- cgit v1.1