diff options
| author | dkf <donal.k.fellows@manchester.ac.uk> | 2023-12-04 13:33:22 (GMT) |
|---|---|---|
| committer | dkf <donal.k.fellows@manchester.ac.uk> | 2023-12-04 13:33:22 (GMT) |
| commit | 29a2ae99530a0d3934ece8ede3bd462f81e8c7d4 (patch) | |
| tree | e7dbb1339a2a5005f8ea795c0c6434ab778c997f /generic/tclVar.c | |
| parent | 1a022cd6633ccf0eb2d9ca267203d2a6297aee72 (diff) | |
| download | tcl-29a2ae99530a0d3934ece8ede3bd462f81e8c7d4.zip tcl-29a2ae99530a0d3934ece8ede3bd462f81e8c7d4.tar.gz tcl-29a2ae99530a0d3934ece8ede3bd462f81e8c7d4.tar.bz2 | |
Much more testing, semantic tweak
Diffstat (limited to 'generic/tclVar.c')
| -rw-r--r-- | generic/tclVar.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/generic/tclVar.c b/generic/tclVar.c index 1f73316..854f9e6 100644 --- a/generic/tclVar.c +++ b/generic/tclVar.c @@ -129,6 +129,7 @@ static const char MISSINGNAME[] = "missing variable name"; static const char ISARRAYELEMENT[] = "name refers to an element in an array"; static const char ISCONST[] = "variable is a constant"; +static const char EXISTS[] = "variable already exists"; /* * A test to see if we are in a call frame that has local variables. This is @@ -4880,7 +4881,7 @@ Tcl_ConstObjCmd( return TCL_ERROR; } if (TclIsVarArrayElement(varPtr)) { - if (!varPtr->value.objPtr) { + if (TclIsVarUndefined(varPtr)) { CleanupVar(varPtr, arrayPtr); } TclObjVarErrMsg(interp, part1Ptr, NULL, "make constant", ISARRAYELEMENT, -1); @@ -4889,21 +4890,28 @@ Tcl_ConstObjCmd( } /* - * TODO: Check if the variable is the same as it was, to match TIP feature. - * Or make const's ability to write to the variable a documented feature. + * If already exists, either a constant (no problem) or an error. */ - if (!TclIsVarUndefined(varPtr) && TclIsVarConstant(varPtr)) { - varPtr->flags &= !VAR_CONSTANT; + if (!TclIsVarUndefined(varPtr)) { + if (TclIsVarConstant(varPtr)) { + return TCL_OK; + } + TclObjVarErrMsg(interp, part1Ptr, NULL, "make constant", EXISTS, -1); + Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "VAR", (void *)NULL); + return TCL_ERROR; } + + /* + * Make the variable and flag it as a constant. + */ if (TclPtrSetVar(interp, (Tcl_Var) varPtr, NULL, objv[1], NULL, objv[2], TCL_LEAVE_ERR_MSG) == NULL) { - varPtr->flags |= VAR_CONSTANT; if (TclIsVarUndefined(varPtr)) { CleanupVar(varPtr, arrayPtr); } return TCL_ERROR; }; - varPtr->flags |= VAR_CONSTANT; + TclSetVarConstant(varPtr); return TCL_OK; } |
