Menu

#24 Incorrect obj type - arrays in a proc

1.0
accepted
None
Bug
2019-06-24
2019-05-23
Pizarro
No

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
}

Discussion

  • Pizarro

    Pizarro - 2019-05-28

    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"

        upvar 0 {V(7)} T
        upvar 0 {V(7)} TA
        ##nagelfar variable TA _obj,myACmd
        upvar 0 {V(8)} TB
        ##nagelfar variable TB _obj,myBCmd
    
        $T  v1
        $T  v1 v2
        $TA v1
        $TA v1 v2
        $TB v1
        $TB v1 v2
    
     
  • Peter Spjuth

    Peter Spjuth - 2019-06-24
    • status: open --> accepted
    • assigned_to: Peter Spjuth
     
  • Peter Spjuth

    Peter Spjuth - 2019-06-24

    That was a lot to digest. Type checking in array members is a tricky thing.

     

Log in to post a comment.

MongoDB Logo MongoDB