Index: doc/SetVar.3
===================================================================
RCS file: /cvsroot/tcl/tcl/doc/SetVar.3,v
retrieving revision 1.8
diff -u -r1.8 SetVar.3
--- doc/SetVar.3	18 Jul 2003 16:56:41 -0000	1.8
+++ doc/SetVar.3	13 Aug 2004 14:18:45 -0000
@@ -221,6 +221,9 @@
 the list element is going to be the first element in a list or
 sublist (i.e. the variable's current value is empty, or contains
 the single character ``{'', or ends in `` }'').
+When appending, the original value of the variable must also be
+a valid list, so that the operation is the appending of a new
+list element onto a list.
 .PP
 \fBTcl_GetVar\fR and \fBTcl_GetVar2\fR
 return the current value of a variable.
Index: generic/tclTest.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclTest.c,v
retrieving revision 1.82
diff -u -r1.82 tclTest.c
--- generic/tclTest.c	19 May 2004 10:38:24 -0000	1.82
+++ generic/tclTest.c	13 Aug 2004 14:18:46 -0000
@@ -319,6 +319,8 @@
 			    Tcl_Interp *interp, int argc, CONST char **argv));
 static int		TestsetCmd _ANSI_ARGS_((ClientData dummy,
 			    Tcl_Interp *interp, int argc, CONST char **argv));
+static int		TestseterrorcodeCmd _ANSI_ARGS_((ClientData dummy,
+			    Tcl_Interp *interp, int argc, CONST char **argv));
 static int		TestsetobjerrorcodeCmd _ANSI_ARGS_((
 			    ClientData dummy, Tcl_Interp *interp,
 			    int objc, Tcl_Obj *CONST objv[]));
@@ -670,6 +672,8 @@
             (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
     Tcl_CreateCommand(interp, "testseterr", TestsetCmd,
             (ClientData) TCL_LEAVE_ERR_MSG, (Tcl_CmdDeleteProc *) NULL);
+    Tcl_CreateCommand(interp, "testseterrorcode", TestseterrorcodeCmd,
+	    (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
     Tcl_CreateObjCommand(interp, "testsetobjerrorcode", 
 	    TestsetobjerrorcodeCmd, (ClientData) 0,
 	    (Tcl_CmdDeleteProc *) NULL);
@@ -3890,11 +3894,46 @@
 /*
  *----------------------------------------------------------------------
  *
+ * TestseterrorcodeCmd --
+ *
+ *	This procedure implements the "testseterrorcodeCmd".
+ *	This tests up to five elements passed to the
+ *	Tcl_SetErrorCode command.
+ *
+ * Results:
+ *	A standard Tcl result. Always returns TCL_ERROR so that
+ *	the error code can be tested.
+ *
+ * Side effects:
+ *	None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+	/* ARGSUSED */
+static int
+TestseterrorcodeCmd(dummy, interp, argc, argv)
+    ClientData dummy;			/* Not used. */
+    Tcl_Interp *interp;			/* Current interpreter. */
+    int argc;				/* Number of arguments. */
+    CONST char **argv;			/* Argument strings. */
+{
+    if (argc > 6) {
+	Tcl_SetResult(interp, "too many args", TCL_STATIC);
+	return TCL_ERROR;
+    }
+    Tcl_SetErrorCode(interp, argv[1], argv[2], argv[3], argv[4],
+	    argv[5], NULL);
+    return TCL_ERROR;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
  * TestsetobjerrorcodeCmd --
  *
  *	This procedure implements the "testsetobjerrorcodeCmd".
- *	This tests up to five elements passed to the
- *	Tcl_SetObjErrorCode command.
+ *	This tests the Tcl_SetObjErrorCode function.
  *
  * Results:
  *	A standard Tcl result. Always returns TCL_ERROR so that
Index: generic/tclVar.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclVar.c,v
retrieving revision 1.87
diff -u -r1.87 tclVar.c
--- generic/tclVar.c	23 Jul 2004 18:32:06 -0000	1.87
+++ generic/tclVar.c	13 Aug 2004 14:18:46 -0000
@@ -1566,7 +1566,7 @@
     CONST char *part2;		/* If non-NULL, gives the name of an element
 				 * in the array part1. */
     Tcl_Obj *newValuePtr;	/* New value for variable. */
-    CONST int flags;			/* OR-ed combination of TCL_GLOBAL_ONLY,
+    CONST int flags;		/* OR-ed combination of TCL_GLOBAL_ONLY,
 				 * and TCL_LEAVE_ERR_MSG bits. */
 {
     Interp *iPtr = (Interp *) interp;
@@ -1625,8 +1625,11 @@
      * "copy on write".
      */
 
+    if (flags & TCL_LIST_ELEMENT && !(flags & TCL_APPEND_VALUE)) {
+	TclSetVarUndefined(varPtr);
+    }
     oldValuePtr = varPtr->value.objPtr;
-    if (flags & TCL_APPEND_VALUE) {
+    if (flags & (TCL_APPEND_VALUE|TCL_LIST_ELEMENT)) {
 	if (TclIsVarUndefined(varPtr) && (oldValuePtr != NULL)) {
 	    Tcl_DecrRefCount(oldValuePtr);     /* discard old value */
 	    varPtr->value.objPtr = NULL;
Index: tests/result.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/result.test,v
retrieving revision 1.8
diff -u -r1.8 result.test
--- tests/result.test	19 May 2004 10:49:47 -0000	1.8
+++ tests/result.test	13 Aug 2004 14:18:47 -0000
@@ -65,27 +65,50 @@
     testsaveresult free {set x 42} 1
 } {42}
 
-test result-4.1 {Tcl_SetObjErrorCode - one arg} {testsaveresult} {
+::tcltest::testConstraint testsetobjerrorcode \
+	[expr {[info commands testsetobjerrorcode] != {}}]
+
+test result-4.1 {Tcl_SetObjErrorCode - one arg} {testsetobjerrorcode} {
     catch {testsetobjerrorcode 1}
     list [set errorCode]
 } {1}
-test result-4.2 {Tcl_SetObjErrorCode - two args} {testsaveresult} {
+test result-4.2 {Tcl_SetObjErrorCode - two args} {testsetobjerrorcode} {
     catch {testsetobjerrorcode 1 2}
     list [set errorCode]
 } {{1 2}}
-test result-4.3 {Tcl_SetObjErrorCode - three args} {testsaveresult} {
+test result-4.3 {Tcl_SetObjErrorCode - three args} {testsetobjerrorcode} {
     catch {testsetobjerrorcode 1 2 3}
     list [set errorCode]
 } {{1 2 3}}
-test result-4.4 {Tcl_SetObjErrorCode - four args} {testsaveresult} {
+test result-4.4 {Tcl_SetObjErrorCode - four args} {testsetobjerrorcode} {
     catch {testsetobjerrorcode 1 2 3 4}
     list [set errorCode]
 } {{1 2 3 4}}
-test result-4.5 {Tcl_SetObjErrorCode - five args} {testsaveresult} {
+test result-4.5 {Tcl_SetObjErrorCode - five args} {testsetobjerrorcode} {
     catch {testsetobjerrorcode 1 2 3 4 5}
     list [set errorCode]
 } {{1 2 3 4 5}}
 
+::tcltest::testConstraint testseterrorcode \
+	[expr {[info commands testseterrorcode] != {}}]
+
+test result-5.1 {Tcl_SetErrorCode - one arg} testseterrorcode {
+    catch {testseterrorcode 1}
+    set errorCode
+} 1
+test result-5.2 {Tcl_SetErrorCode - one arg, list quoting} testseterrorcode {
+    catch {testseterrorcode {a b}}
+    set errorCode
+} {{a b}}
+test result-5.3 {Tcl_SetErrorCode - one arg, list quoting} testseterrorcode {
+    catch {testseterrorcode \{}
+    llength $errorCode
+} 1
+test result-5.4 {Tcl_SetErrorCode - two args, list quoting} testseterrorcode {
+    catch {testseterrorcode {a b} c}
+    set errorCode
+} {{a b} c}
+
 # cleanup
 ::tcltest::cleanupTests
 return
