Menu

#290 Class Procedures Can Be Called Like Methods

4.0*
open
nobody
None
5
2019-03-28
2019-03-28
No

Class procedures can be erroneously called like methods. They even have access to instance variables:

package require Itcl

itcl::class A {

    public proc hello {} {
        puts hello
    }

    private variable var there

    public proc there {} {
        puts $var
    }
}

# Works as expected.
A::hello

# Works, but shouldn't.
set a [A #auto]
$a hello

# Can even access instance variables.
$a there

With Itcl 4.1.2:

hello
hello
there

With Itcl 3.4:

hello
bad option "hello": should be one of...
  a0 cget -option
  a0 configure ?-option? ?value -option value...?
  a0 isa className
    while executing
"$a hello "

Discussion


Log in to post a comment.