Tcl Source Code

View Ticket
Login
Ticket UUID: 477c24cb39e3c502dec0329583256072211ea4d3
Title: rename ::set and lose custom return options
Type: Bug Created on: 2016-08-31 11:17:04
Submitter: pooryorick Assigned to: dgp
Subsystem: 18. Commands M-Z Severity: Minor
Priority: 3 Low Last modified: 2016-10-09 14:51:26
Status: Open Closed by: nobody
Resolution: None Closed on:
Version: 8.6.6
Description:

In the following example, -custom1 1 is missing from $options in p2

namespace eval ns1 {
	rename ::set [namespace current]::set
	interp alias {} ::set {} [namespace current]::set
}

proc p1 {} {
	return -options {-custom1 1} {result 1} 
}

proc p2 {} {
	catch {set status [p1]} result options
	puts $options
} 

p2

User Comments:
aspect added on 2016-09-01 13:04:34:
This thread seems to go deep:

proc p0 {} {
	list result 0
}
proc p1 {} {
	return -options {-custom1 1} {result 1}
}

proc t0 {} {
	list [catch {p1; p0} r o] $r $o
}

proc t1 {} {
	list [catch {p1} r o] $r $o
}

proc t2 {} {
	list [catch {p1; list result 2} r o] $r $o
}

puts [t0]
puts [t1]
puts [t2]
# 0 {result 0} {-code 0 -level 0}
# 0 {result 1} {-custom1 1 -code 0 -level 0}
# 0 {result 2} {-custom1 1 -code 0 -level 0}
</verbatim></code>

It looks on first glance like bytecode instructions are not resetting returnOpts.  Or are t1 and t2 expected?

aspect added on 2016-09-01 13:24:02:
Related?

% list [catch {unset -nocomplain t} r o] $r $o
0 {} {-code 0 -level 0}
% list [catch {incr t} r o] $r $o
0 1 {-code 0 -level 0 -errorcode {TCL READ VARNAME}}
% list [catch {incr t} r o] $r $o
0 2 {-code 0 -level 0}

dgp added on 2016-09-01 17:05:38:
Some of the comments here are Dups of

http://core.tcl.tk/tcl/tktview?name=2433843

Not sure about the original report yet.

dgp added on 2016-09-01 17:31:00:
Here's another demo, that I find more focused:

proc p1 {} {return -custom1 1 1}
proc p2 {b} {
    if {$b} {
        catch {set status [p1]} m o
    } else {
        set set set
        catch {$set status [p1]} m o
    }
    return $o
}
puts [p2 0]
puts [p2 1]

Demonstrates a clear difference in bytecode
execution compared to non-bytecode script evaluation.
They ought to be the same and they are not, so yes
there's a bug.

This leads to an unsettling debate over which
is correct.  How long should a return
option survive when return code is TCL_OK ?

dgp added on 2016-09-01 17:35:49:
Change p1 to:

proc p1 {} {return -custom 1 -code 10 1}

so that a custom code is used along with
a custom option (which was the use case)
and see that that case preserves the option
in both branches.

pooryorick added on 2016-09-02 08:06:24:
So the bug is the inverse of what I originally reported.  It's not that <code>-custom1 1</code> is missing from <code>$options</code>, but that it's present if the example doesn't rename the "::set" command.  Thank you for the analysis.

dkf added on 2016-10-09 14:51:26:

Tempted to suggest not fixing given the performance impact it would have, but dgp invented the custom return option machinery so he can worry about the impact.