diff options
-rw-r--r-- | generic/tclExecute.c | 7 | ||||
-rw-r--r-- | generic/tclObj.c | 7 | ||||
-rw-r--r-- | tests/expr.test | 6 |
3 files changed, 20 insertions, 0 deletions
diff --git a/generic/tclExecute.c b/generic/tclExecute.c index fab8590..8e6f4b5 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -9121,6 +9121,13 @@ IllegalExprOperandType( } if (GetNumberFromObj(NULL, opndPtr, &ptr, &type) != TCL_OK) { + Tcl_ObjTypeLengthProc *lengthProc = TclObjTypeHasProc(opndPtr, lengthProc); + if (lengthProc && lengthProc(opndPtr) > 1) { + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "can't use a list as operand of \"%s\"", op)); + Tcl_SetErrorCode(interp, "ARITH", "DOMAIN", "list", (char *)NULL); + return; + } description = "non-numeric string"; } else if (type == TCL_NUMBER_NAN) { description = "non-numeric floating-point value"; diff --git a/generic/tclObj.c b/generic/tclObj.c index 7155ebb..dc129ab 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -3679,6 +3679,13 @@ Tcl_GetNumberFromObj( void **clientDataPtr, int *typePtr) { + Tcl_ObjTypeLengthProc *lengthProc = TclObjTypeHasProc(objPtr, lengthProc); + if (lengthProc && lengthProc(objPtr) != 1) { + if (interp) { + Tcl_SetObjResult(interp, Tcl_NewStringObj("expected number but got a list", -1)); + } + return TCL_ERROR; + } do { if (TclHasInternalRep(objPtr, &tclDoubleType)) { if (isnan(objPtr->internalRep.doubleValue)) { diff --git a/tests/expr.test b/tests/expr.test index bfefde3..a13250b 100644 --- a/tests/expr.test +++ b/tests/expr.test @@ -501,6 +501,9 @@ test expr-11.13a {CompileAddExpr: runtime error} !ieeeFloatingPoint { test expr-11.13b {CompileAddExpr: runtime error} ieeeFloatingPoint { list [catch {expr {2.3/0.0}} msg] $msg } {0 Inf} +test expr-11.14 {CompileAddExpr: runtime error} { + list [catch {expr {24.0+[lseq 2 4]}} msg] $msg +} {1 {can't 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 @@ -7227,6 +7230,9 @@ test expr-47.13 {isqrt and floating point rounding (Bug 2143288)} { } set trouble } {} +test expr-47.14 {isqrt() - lseq} { + list [catch {expr {isqrt([lseq 1 3])}} result] $result +} {1 {expected number but got a list}} test expr-48.1 {Bug 1770224} { expr {-0x8000000000000001 >> 0x8000000000000000} |