From aa4357dad884020d78319f48ce04000f51562c2a Mon Sep 17 00:00:00 2001 From: pooryorick Date: Mon, 7 Oct 2024 21:47:14 +0000 Subject: In Tcl_GetNumberFromObj() change the dictionary length check from > 1 to > 0 to determine whether the value can be parsed as a number, and make corresponding changes in tclObj.c and expr.test. --- generic/tclExecute.c | 2 +- generic/tclObj.c | 2 +- tests/expr.test | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 6910c29..ce2a908 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -9112,7 +9112,7 @@ IllegalExprOperandType( Tcl_Size length; if (TclHasInternalRep(opndPtr, &tclDictType)) { Tcl_DictObjSize(NULL, opndPtr, &length); - if (length > 1) { + if (length > 0) { listRep: Tcl_SetObjResult(interp, Tcl_ObjPrintf( "cannot use a list as %soperand of \"%s\"", ord, op)); diff --git a/generic/tclObj.c b/generic/tclObj.c index 5b7e5bd..7480778 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -3708,7 +3708,7 @@ Tcl_GetNumberFromObj( /* Handle dict separately, because it doesn't have a lengthProc */ if (TclHasInternalRep(objPtr, &tclDictType)) { Tcl_DictObjSize(NULL, objPtr, &length); - if (length > 1) { + if (length > 0) { listRep: if (interp) { Tcl_SetObjResult(interp, Tcl_NewStringObj("expected number but got a list", -1)); diff --git a/tests/expr.test b/tests/expr.test index 7563757..1d7c412 100644 --- a/tests/expr.test +++ b/tests/expr.test @@ -509,7 +509,7 @@ test expr-11.15 {CompileAddExpr: runtime error} { } {1 {cannot use non-numeric string "1 2 3" as left operand of "+"}} test expr-11.16 {CompileAddExpr: runtime error} { list [catch {expr {~[dict create foo bar]}} msg] $msg -} {1 {cannot use non-numeric string "foo bar" as operand of "~"}} +} {1 {cannot use a list as operand of "~"}} test expr-12.1 {CompileMultiplyExpr: just unary expr} {expr ~4} -5 test expr-12.2 {CompileMultiplyExpr: just unary expr} {expr --5} 5 -- cgit v0.12