Tcl Source Code

View Ticket
Login
Ticket UUID: 1445454
Title: incr on undefined array fails in procedures
Type: Bug Created on: 2006-03-08 08:30:51
Submitter: avl42 Assigned to: dgp
Subsystem: 47. Bytecode Compiler Severity:
Priority: 9 Immediate Last modified: 2006-03-09 17:34:50
Status: Closed Closed by: dgp
Resolution: Fixed Closed on: 2006-03-08 16:07:47
Version: obsolete: 8.5a4
Description:
on a fresh tclsh8.5:
% incr foo(1)
1
# so far so good, but:
% proc abc {} { incr foo(1) }
% abc
can't read "foo(1)": no such variable

(with scalars it works both ways)
User Comments:
dkf added on 2006-03-08 16:02:48:
Logged In: YES 
user_id=79902

Looks to be a difference in behaviour between bytecodes. :-(

% set tcl_traceExec 3; time {incr foo(1)}; set tcl_traceExec 0
1: (10) invoking "time" "incr foo(1)"

Executing ByteCode 0x814d960, refCt 2, epoch 0, interp
0x8158d50 (epoch 0)
  Source: "incr foo(1)"
  Cmds 1, src 11, inst 7, litObjs 2, aux 0, stkDepth 2,
code/src 10.91
  Code 120 = header 100+inst 7+litObj 8+exc 0+aux 0+cmdMap 4
  Starting stack top=1
 2:  1 (0) push1 0      # "foo"
 2:  2 (0) push1 0 => "foo"
 2:  2 (2) push1 1      # "1"
 2:  3 (2) push1 1 => "1"
 2:  3 (4) incrArrayStkImm +1
 2:  3 (4) incrArrayStkImm "foo(1)" (by 1) => 1
 2:  2 (6) done
 2:  2 (6) done => return code=0, result="1"

   ... no enclosing catch, returning TCL_OK
0
% set tcl_traceExec 3;catch { abc }; set tcl_traceExec 0
1: (18) invoking "abc"
Calling proc "abc"

Executing ByteCode 0x814d260, refCt 2, epoch 0, interp
0x8158d50 (epoch 0)
  Source: "incr foo(1)"
  Cmds 1, src 11, inst 6, litObjs 1, aux 0, stkDepth 1,
code/src 10.91
  Code 120 = header 100+inst 6+litObj 4+exc 0+aux 0+cmdMap 4
  Proc 0x816fb90, refCt 2, args 0, compiled locals 1
  Starting stack top=24
 2: 24 (0) push1 0      # "1"
 2: 25 (0) push1 0 => "1"
 2: 25 (2) incrArray1Imm %v0 +1         # var "foo"
 2: 25 (2) incrArray1Imm 0 "1" (by 1) => ERROR: can't read
"foo(1)": no such v
   ... no enclosing catch, returning TCL_ERROR
0

msofer added on 2006-03-08 16:58:59:
Logged In: YES 
user_id=148712

Note that the problem is the non-existing array, and not the
non-existing component:

% proc x {} {incr a(1)}
% proc y {} {set a(2) 1; incr a(1)}
% x
can't read "a(1)": no such variable
% y
1

dkf added on 2006-03-08 20:56:04:
Logged In: YES 
user_id=79902

INST_INCR_ARRAY1 also takes the offending path in TEBC.

I believe the problem is the call to TclLookupArrayElement
at line 2433; it should create the array if it doesn't
already exist (like 'set'). If I change the 'createArray'
flag to '1', this problem goes away and the test suite still
passes (with only the failures that were there before; which
is itself an indication there's not enough tests).

dgp added on 2006-03-08 22:25:04:
Logged In: YES 
user_id=80530


Gee... who would think
I could miss one of the
paths through the
INST_INCR_* tangle?  :/

dgp added on 2006-03-08 23:07:47:
Logged In: YES 
user_id=80530


fix committed

avl42 added on 2006-03-09 17:34:50:
Logged In: YES 
user_id=830354

Wow! Fixed within the third of a day!
Thanks!