Tcl Source Code

View Ticket
Login
Ticket UUID: a122627849570b9175e6a2359560d1204733a854
Title: procedure 'parray' doesn't check for an array
Type: Bug Version: 8.4
Submitter: anonymous Created on: 2013-11-22 13:45:46
Subsystem: 38. Init - Library - Autoload Assigned To: dkf
Priority: 3 Low Severity: Minor
Status: Closed Last Modified: 2013-11-24 20:50:22
Resolution: Invalid Closed By: jan.nijtmans
    Closed on: 2013-11-24 20:50:22
Description: (text/html)
There's a bug in the built-in 'parray' procedure of Tcl 8.4.
<br />
The 'parray' procedure check if the variable is an array, and if it is not, then it tries to print it's content instead of it's name.

 

Code example:
<pre>
proc array_to_list {arr_VarName} {
                upvar $arr_VarName arr
                if [array exists arr] {
                                set tmp [array get arr]
                                parray arr
                                unset arr
                                parray arr
                                array set arr [array get tmp]
                                return 1
                }
                return 0
}

set b(a) "5"
set b(c) "asdas"
set b(dd) "al94i"

if [array_to_list b] {
                puts $b
} else {
                puts "BAAAAAAA"
}
</pre>

Output example:
<pre>
arr(a)  = 5
arr(c)  = asdas
arr(dd) = al94i

"arr" isn't an array
    while executing
"error "\"$a\" isn't an array""
    (procedure "parray" line 4)
    invoked from within
"parray arr"
    invoked from within
"if [array exists arr] {
                                set tmp [array get arr]
                                parray arr
                                unset arr
                                parray arr
                                array set arr [array get tmp]
                                return 1
                }"
    (procedure "array_to_list" line 3)
    invoked from within
"array_to_list b"
    invoked from within
"if [array_to_list b] {
                puts $b
} else {
                puts "BAAAAAAA"
}"
    (file ".\test.tcl" line 22)
</pre>

The line "error "\"$a\" isn't an array"" has the error, which is relevant to the second 'parray arr' line that is in the 'array_to_list' procedure.
<br />
ActiveState ActiveTcl <br />8.4.20.0.297203                                              Jun 05, 2013
User Comments: jan.nijtmans added on 2013-11-24 20:50:22:
Yes that makes sense! Indeed, less confusing. Thanks!

dkf added on 2013-11-24 18:37:38: (text/html)
“Fixed” the error trace message in 8.5 and 8.6. No sense in confusing people unnecessarily.

dkf added on 2013-11-24 17:37:09: (text/html)
Actually, it makes sense to make that change; it's not an error in <tt>parray</tt> itself, so much as its caller. It also doesn't break any existing tests in 8.5 (8.4 being closed to changes now…)

dkf added on 2013-11-24 17:20:01: (text/html)
I suppose we could use <tt>return -code error</tt> instead of <tt>error</tt>. Like it's important.

jan.nijtmans added on 2013-11-22 16:05:44: (text/x-fossil-wiki)
This error message:

"arr" isn't an array

looks perfectly OK to me.