Incorrect obj type - arrays in a proc
Brought to you by:
pspjuth
type definition are inconsistent / incorrect, depending on where the code is (i.e. if it is in a proc).
Tested on: Version 1.3.0 2018-10-03 and "interactive demo" on http://nagelfar.sourceforge.net/
example code
V(1) , V(3), V(5) and V(7) should be obj,myACmd
V(2) , V(4), V(6) and V(8) should be obj,myBCmd
In the following example, V(3) and V(7) are assigned an incorrect type .
They should be obj,myACmd (not myBCmd)
##nagelfar syntax a
##nagelfar return a _obj,myACmd
##nagelfar syntax b
##nagelfar return b _obj,myBCmd
##nagelfar syntax _obj,myACmd x
##nagelfar syntax _obj,myBCmd x x
variable V
set V(1) [a]
set V(2) [b]
# This analysis is correct
$V(1) v1
$V(1) v1 v2
$V(2) v1
$V(2) v1 v2
# These cause problems with oo types
if { ![info exists V(3)] } { set V(3) [a] }
if { ![info exists V(4)] } { set V(4) [b] }
# this analysis is incorrect
$V(3) v1
$V(3) v1 v2
$V(4) v1
$V(4) v1 v2
# These cause problems with oo types
if { ![info exists V(5)] } { set V(5) [a] }
if { ![info exists V(6)] } { set V(6) [b] }
# but can be corrected with
##nagelfar variable V(5) _obj,myACmd
##nagelfar variable V(6) _obj,myBCmd
$V(5) v1
$V(5) v1 v2
$V(6) v1
$V(6) v1 v2
# but we can't do a workarround, if this problem is in a proc
##nagelfar variable V(7) _obj,myACmd
##nagelfar variable V(8) _obj,myBCmd
proc T2 { args } {
variable V
# These cause problems with oo types
if { ![info exists V(7)] } { set V(7) [a] }
if { ![info exists V(8)] } { set V(8) [b] }
##nagelfar variable V(7) _obj,myACmd
##nagelfar variable V(8) _obj,myBCmd
$V(7) v1
$V(7) v1 v2
$V(8) v1
$V(8) v1 v2
}
There is a work-arround for this issue.
If you do a zero level upvar, you can then tell nagelfar what the object type is.
e.g. add the following code to the end of the "proc"
That was a lot to digest. Type checking in array members is a tricky thing.