summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclCmdIL.c8
-rw-r--r--tests/lpop.test33
2 files changed, 27 insertions, 14 deletions
diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c
index 4e6a947..51380e9 100644
--- a/generic/tclCmdIL.c
+++ b/generic/tclCmdIL.c
@@ -2589,6 +2589,14 @@ Tcl_LpopObjCmd(
*/
if (objc == 2) {
+ if (!listLen) {
+ /* empty list, throw the same error as with index "end" */
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ "index \"end\" out of range", -1));
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "INDEX"
+ "OUTOFRANGE", NULL);
+ return TCL_ERROR;
+ }
elemPtr = elemPtrs[listLen - 1];
Tcl_IncrRefCount(elemPtr);
} else {
diff --git a/tests/lpop.test b/tests/lpop.test
index 89b651c..3e28978 100644
--- a/tests/lpop.test
+++ b/tests/lpop.test
@@ -16,6 +16,7 @@ if {[lsearch [namespace children] ::tcltest] == -1} {
namespace import -force ::tcltest::*
}
+unset -nocomplain no; # following tests expecting var "no" does not exists
test lpop-1.1 {error conditions} -returnCodes error -body {
lpop no
} -result {can't read "no": no such variable}
@@ -23,32 +24,36 @@ test lpop-1.2 {error conditions} -returnCodes error -body {
lpop no 0
} -result {can't read "no": no such variable}
test lpop-1.3 {error conditions} -returnCodes error -body {
- set no "x {}x"
- lpop no
+ set l "x {}x"
+ lpop l
} -result {list element in braces followed by "x" instead of space}
test lpop-1.4 {error conditions} -returnCodes error -body {
- set no "x y"
- lpop no -1
+ set l "x y"
+ lpop l -1
} -result {index "-1" out of range}
+test lpop-1.4b {error conditions (also check SF on empty list variable, bug [234d6c811d])} -body {
+ set l "x y"
+ list [lpop l] [lpop l] [catch {lpop l} v] $v [catch {lpop l 0} v] $v $l
+} -result {y x 1 {index "end" out of range} 1 {index "0" out of range} {}}
test lpop-1.5 {error conditions} -returnCodes error -body {
- set no "x y z"
- lpop no 3
+ set l "x y z"
+ lpop l 3
} -result {index "3" out of range} ;#-errorCode {TCL OPERATION LPOP BADINDEX}
test lpop-1.6 {error conditions} -returnCodes error -body {
- set no "x y"
- lpop no end+1
+ set l "x y"
+ lpop l end+1
} -result {index "end+1" out of range}
test lpop-1.7 {error conditions} -returnCodes error -body {
- set no "x y"
- lpop no {}
+ set l "x y"
+ lpop l {}
} -match glob -result {bad index *}
test lpop-1.8 {error conditions} -returnCodes error -body {
- set no "x y"
- lpop no 0 0 0 0 1
+ set l "x y"
+ lpop l 0 0 0 0 1
} -result {index "1" out of range}
test lpop-1.9 {error conditions} -returnCodes error -body {
- set no "x y"
- lpop no {1 0}
+ set l "x y"
+ lpop l {1 0}
} -match glob -result {bad index *}
test lpop-2.1 {basic functionality} -body {