try/finally bytecode optimizer incorrect order of operations
Closed / Fixed27520c9b17116d8d34c1874e4e9ec9d350ad579eCreated 5 years agoUpdated 5 years ago
Descriptionplain2022-04-21 21:30:47
There appears to be a problem with the bytecode optimizer for [try]. If the argument after "finally" contains substitutions, they are not evaluated until it actually comes time to execute the "finally" block.
Consider:
try {puts a} finally [puts b]
This should print "b a" (newline in between) because the [puts b] needs to be evaluated in the process of assembling the command line, before even executing it. However, it prints "a b" instead.
If the command line is instead written:
{*}[list] try {puts a} finally [puts b]
it prints "b a" as expected. This is because the bizarre invocation of [list] bypasses the bytecode optimizer, allowing the normal Tcl order of operations to prevail.
Referenced by4
9427d5662emerge 8.6 (fixes [27520c9b17]) check-in2022-04-26 13:27:16642ae7905bcloses bug [27520c9b17] check-in2022-04-26 12:28:01fba9450772fixes compilation of try-command [27520c9b17]: compile only if finaly token is simple check-in2022-04-26 12:03:41b6e28a1636added test illustrating bug [27520c9b17] check-in2022-04-26 12:03:22
sebreswiki2022-04-26 12:11:36
I fixed that (already in 2019) but somehow missed to provide the fix in tcl-core.
Rebased now to related fossil revision (could be safely merged in current 8.6) as branch bug-27520c9b17.
sebreswiki2022-04-26 12:29:16
Fixed (merged in current 8.6)
Log in (anonymous is fine) to add a comment.