Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2012-08-03
05:21 • Ticket [3553586fff] Wrong argument to return command doesnt return error sta... artifact: 8571180d4c user: ferrieux
04:03 • Ticket [3553586fff]: 4 changes artifact: 7e1ac61186 user: dkf
2012-08-02
23:54 • Ticket [3553586fff]: 4 changes artifact: 20f5317ab4 user: ferrieux
21:22 • Closed ticket [3553586fff]. artifact: 7da802a8ed user: dgp
21:12 • Ticket [3553586fff]: 4 changes artifact: 197e73e7e8 user: ferrieux
21:05 • Ticket [3553586fff]: 5 changes artifact: 9006d89087 user: dkf
11:47 • New ticket [3553586fff]. artifact: 656c768fdb user: jmcuaz

Wrong argument to return command doesnt return error

Closed / Invalid3553586fffffffffffffffffffffffffffffffffCreated 14 years agoUpdated 14 years ago
Descriptionplain2012-08-02 11:47:35
In a proc we did the following mistake: 

return expr {[dict exists $dict $key] ? [dict get $dict $key] : 0}
 wich ought to be :
return [expr {[dict exists $dict $key] ? [dict get $dict $key] : 0}]

The surprise is that the execution of the faulty code returns an empty string and not an error.
It might be that the 2nd word "epr" has been intrepreted as an option argument for the third form of return syntax (i.e. return ?option value ...? ?result?), but shoudn't any option begin with a dash ?

On an other (but related) subject, the doc is not very clear about the differences betwen the 2nd (i.e. return ?-code code? ?result?) an third form (return ?option value ...? ?result?) of the syntax of return command : are each form exclusive from the other or can they be mixed together as shown in the examples witten in TIP 90 ?

Many thanks

Jean-Marie
dkfplain2012-08-02 21:05:42
assign to the master of the rewritten [return]
ferrieuxplain2012-08-02 21:12:27
The generated bytecode for "return a b" is interesting:

% proc f {} {return a b}
% ::tcl::unsupported::disassemble proc f
ByteCode 0x0x83a0d28, refCt 1, epoch 5, interp 0x0x834a770 (epoch 5)
  Source "return a b"
  Cmds 1, src 10, inst 14, litObjs 2, aux 0, stkDepth 2, code/src 0.00
  Proc 0x0x83ba258, refCt 1, args 0, compiled locals 0
  Commands 1:
      1: pc 0-12, src 0-9
  Command 1: "return a b"
    (0) push1 0         # ""
    (2) push1 1         # "a b"
    (4) returnImm +0 1 
    (13) done
dgpplain2012-08-02 21:22:11
allow_comments - 1

Not a bug.  [return] accepts any string as an option, for maximum freedom in use by extensions
and packages.  As proposed (TIP 90) and documented "any values at all are acceptable"
ferrieuxplain2012-08-02 23:54:25
That's a regrettable TIP. I'm sure none of us has ever seen, nor will ever see, code using a return option not prefixed by a dash; while the failure scenario reported here is very common, and goes out of reach due to this move. What about a TIP "-90" ?
dkfplain2012-08-03 04:03:27
We most surely do not wish to remove the whole of TIP 90.

But this is leaving the domain of bug reports. Open a FRQ or write a TIP if you really wish to pursue this; formally, it's currently Not A Bug as it is exactly intended behavior.
ferrieuxplain2012-08-03 05:21:03
Yes, of course I'm not against the whole of TIP 90, which is no less than the completion of the promise that every language construct is first-class...

And yes I admit that the current report falls under the "works as documented" rule.

It's just that the bit about relaxing -OPTION to ANYTHING was unwarranted overgeneralization. Sadly, this has been the case for so long that it is clearly too late to do anything about it.
Log in (anonymous is fine) to add a comment.