Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2007-09-07
01:13 • Closed ticket [219191ffff]: return in after script causes bogus bgerror plus... artifact: 7f90534210 user: dgp
2004-11-16
05:33 • Ticket [219191ffff]: 1 change artifact: 99485bc20b user: dgp
2004-09-20
04:14 • Ticket [219191ffff]: 4 changes artifact: de5b674802 user: dgp
2003-04-28
22:36 • Ticket [219191ffff]: 4 changes artifact: 314c138c39 user: dgp
2002-03-19
04:56 • Ticket [219191ffff]: 5 changes artifact: dbe198cbaf user: kennykb
2001-11-28
07:05 • Ticket [219191ffff]: 4 changes artifact: 8bb211ba91 user: kennykb
2001-09-14
03:28 • Ticket [219191ffff]: 4 changes artifact: 3c6c05d579 user: dgp
01:57 • Ticket [219191ffff]: 4 changes artifact: 9ca3b60f68 user: dgp
2001-09-10
11:48 • Ticket [219191ffff]: 4 changes artifact: 19b83d34a2 user: dgp
2001-09-08
06:27 • Ticket [219191ffff]: 1 change artifact: bc4fc0f18b user: andreas_kupries
2001-04-05
08:03 • Ticket [219191ffff]: 1 change artifact: 5784627daf user: dgp
2000-11-24
20:24 • Ticket [219191ffff]: 4 changes artifact: 8fd39304be user: dkf
2000-11-14
04:53 • Ticket [219191ffff]: 4 changes artifact: f6392eb9a1 user: dgp
2000-11-13
20:50 • Ticket [219191ffff]: 5 changes artifact: 2fa3d680e8 user: dkf
2000-10-26
05:03 • New ticket [219191ffff]. artifact: 52d2b12220 user: nobody

return in after script causes bogus bgerror

Closed / Fixed219191ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 19 years ago
Descriptionplain2000-10-26 05:03:20
OriginalBugID: 2577 Bug
Version: 8.0.5
SubmitDate: '1999-08-18'
LastModified: '2000-04-03'
Severity: SER
Status: Assigned
Submitter: techsupp
ChangedBy: hobbs
RelatedBugIDs: 3998 750
OS: Solaris
OSVersion: 2.5.1
Machine: Other
FixedDate: '2000-10-25'
ClosedDate: '2000-10-25'


Name: Tedd Hadley

Comments:
The reason for the error seems to be code in tclTimer.c AfterProc:
    
        result =  afterPtr->command);
        if (result != TCL_OK) {
            Tcl_AddErrorInfo(interp, "\n    (\"after\" script)");
            Tcl_BackgroundError(interp);
        }
    
    Tcl_GlobalEval can, of course, return a value other than TCL_OK without
    it being TCL_ERROR -- TCL_RETURN in this case.  I patched my version
    by changing the condition to if(result == TCL_ERROR).  This may or may
    not be the right fix...

ReproducibleScript:
after 0 {
       return
    }
    update

ObservedBehavior:
return in an after script causes a fake error.

DesiredBehavior:
No error expected



wish4.2 didn't complain, but 8.0+ does. 
-- 04/03/2000 hobbs
dkfplain2000-11-13 20:50:43
Return at the global level (which is where after scripts are executed) should always cause an error.
dgpplain2000-11-14 04:53:50
I disagree that [return] should throw an error at
level #0.  That's not what the docs say.  From return(n):
...
DESCRIPTION
     Return immediately from the current procedure (or  top-level
     command or source command), with string as the return value.
...

[return] has behaved this way at least as long as I've
used Tcl (since Tcl 7.4), and I've seen plenty of code
that depends on this behavior.  Notably the use of
[return] to exit a pkgIndex.tcl file before the end
of file is quite useful.
dkfplain2000-11-24 20:24:57
And if the [return] *is* the current top-level command?  In that case, I read the description as being functionally equivalent to something that just has a result of the given string (like [format %s $string] for example.)

IMHO, what [return] does is make the current context terminate with the given message/code/errorInfo/errorCode.  But what this means at the top-level is a little unclear to me.
dgp Ticket [219191ffff]: 1 change [History diff]2001-04-05 08:03:55
andreas_kupries Ticket [219191ffff]: 1 change [History diff]2001-09-08 06:27:03
dgpplain2001-09-10 11:48:17
Logged In: YES 
user_id=80530

Note that TIP 56 is likely to fix this.
dgpplain2001-09-14 01:57:35
Logged In: YES 
user_id=80530

I was wrong.  TIP 56 had no effect.  The original
report identified the cause.

Either we should allow TCL_RETURN to be the return code
from an after script, or when we see it, we should
generate an error message stating that it is not allowed.
As is, the empty error message due to no TCL_ERROR does
not help.
dgpplain2001-09-14 03:28:11
Logged In: YES 
user_id=80530

OK, now I'm having second thoughts about this
specific bug report.  The "Reproducible Script"
submitted above throws an error in Tcl 7.5 and 7.6
as well as in 8.x.  

As Jeff reports above, things are different in Tk 4.2.
I think it's an improvement that Tk 8 is consistent with
Tcl 8, and the incompatible change did occur at a major
version increment for Tk.

I think there's still a bug here in the form of the
empty error message.  That should be corrected.

Beyond that, if there's still a constituency out there
for accepting TCL_RETURN as the result of evaluation
of an [after] script, they ought to file a feature request.
kennykbplain2001-11-28 07:05:46
Logged In: YES 
user_id=99768

We have deeper inconsistencies.

Consider:

% break
invoked "break" outside of a loop
% return -code break
invoked "break" outside of a loop
% continue
invoked "continue" outside of a loop
% return -code continue
invoked "continue" outside of a loop
% return
% return -code return
command returned bad code: 2

Any of the above six commands result in a bgerror with a null message when invoked from [after].
kennykbplain2002-03-19 04:56:22
Logged In: YES 
user_id=99768

Don Porter says that he plans to look at this stuff in the context of
TIP #90: it hits some of the same areas in the code.
dgpplain2003-04-28 22:36:22
Logged In: YES 
user_id=80530

TIP 90 does not change these things.

This is an effect of TCL_RETURN being
handled by TclUpdateReturnInfo if it
is seen at the toplevel only.  Wish event
loop operates at toplevel; event loops
in commands like [update] or [vwait] 
do not.
dgpplain2004-09-20 04:14:06
Logged In: YES 
user_id=80530

TIP 221 is related to the issues
attached to this report.
dgp Ticket [219191ffff]: 1 change [History diff]2004-11-16 05:33:42
dgpplain2007-09-07 01:13:23
Logged In: YES 
user_id=80530
Originator: NO


fixed in HEAD
Log in (anonymous is fine) to add a comment.