From f316d7539c5bb69dc519fc27be251c9ba056c189 Mon Sep 17 00:00:00 2001 From: dgp Date: Tue, 17 Apr 2018 18:34:41 +0000 Subject: [array set] must fire array traces. Don't disrupt that by reporting argument errors too early. --- generic/tclCompCmds.c | 11 +++++++++++ tests/var.test | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/generic/tclCompCmds.c b/generic/tclCompCmds.c index c2b4bdb..9a15ee0 100644 --- a/generic/tclCompCmds.c +++ b/generic/tclCompCmds.c @@ -322,11 +322,22 @@ TclCompileArraySetCmd( */ if (isDataValid && !isDataEven) { + /* Abandon compile and let direct eval raise the error */ + code = TCL_ERROR; + goto done; + + /* + * We used to compile to the bytecode that would throw the error, + * but that was wrong because it would not invoke the array trace + * on the variable. + * PushStringLiteral(envPtr, "list must have an even number of elements"); PushStringLiteral(envPtr, "-errorcode {TCL ARGUMENT FORMAT}"); TclEmitInstInt4(INST_RETURN_IMM, TCL_ERROR, envPtr); TclEmitInt4( 0, envPtr); goto done; + * + */ } /* diff --git a/tests/var.test b/tests/var.test index a9d93ac..d1340f6 100644 --- a/tests/var.test +++ b/tests/var.test @@ -930,6 +930,15 @@ test var-20.9 {[bc1a96407a] array set compiled w/ trace} -setup { test var-20.10 {[bc1a96407a] array set don't compile bad varname} -body { apply {{} {set name foo(bar); array set $name {a 1}}} } -returnCodes error -match glob -result * +test var-20.11 {array set don't compile bad initializer} -setup { + unset -nocomplain foo + trace add variable foo array {set foo(bar) baz;#} +} -body { + catch {array set foo bad} + set foo(bar) +} -cleanup { + unset -nocomplain foo +} -result baz test var-21.0 {PushVarNameWord OBOE in compiled unset} -setup { proc linenumber {} {dict get [info frame -1] line} -- cgit v0.12