supercollider / supercollider

An audio server, programming language, and IDE for sound synthesis and algorithmic composition.
http://supercollider.github.io
GNU General Public License v3.0
5.53k stars 754 forks source link

respondsTo (and consequently tryPerform) don't know about methods added (at runtime) with addUniqueMethod #5662

Open avdrd opened 2 years ago

avdrd commented 2 years ago

Environment

Steps to reproduce

\foo.addUniqueMethod(\bar, { \meh })
\foo.bar // -> meh
\foo.respondsTo(\bar) // false!!

Expected vs. actual behavior

I'd have expected respondsTo to know about those runtime-added methods too. It's not even clear to me how to test for their presence in an object otherwise.

I can't be bothered to file another separate report right now but tryPerform has a similar problem.

\foo.addUniqueMethod(\bar, { \meh })
\foo.tryPerform(\bar) // nil!
try { \foo.bar } // -> meh

So tryPerform also doesn't work for addUniqueMethod-s, and it is perhaps a more serious bug.

Actually tryPerform is implemented in terms of respondsTo:

    tryPerform { arg selector ... args;
        ^if(this.respondsTo(selector),{
            this.performList(selector,args)
        })
    }

So, filing a single bug report for both turned out the right choice since fixing respondsTo will fix tryPerform as well, in this regard.

Alas respondsTo is a native method wrapper for _ObjectRespondsTo, so that will take more than a script kiddie to fix.

telephon commented 2 years ago

As far as I remember, the implementation of addUniqueMethod was left somewhat incomplete, and you correctly observe some of the gaps.