www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - What's wrong with opCall ?

reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
Hello,

Considering my effort on rework of the range API for upcoming 
std.datetime (It's coming, Jonathan, but far slower then I thought).
I was in determined to see where can I get with function-like objects, 
but it seems I'm missing something.
The following program do not compile:
struct S{
     ubyte _d;
     this(ubyte d){
         _d = d;
     }
     int opCall(string a){
         return  _d;
     }
}

void main(){
     S s = S(22);
     assert(s.opCall("A") == 22);
//    s("A");//uncoment to get compile error
}

bug.d(14): Error: constructor bug.S.this (ubyte d) is not callable using 
argument types
bug.d(14): Error: cannot implicitly convert expression ("A") of type 
string to ubyte

So it appears that compiler views it as a call to constructor instead. 
What's the problem?

-- 
Dmitry Olshansky
Nov 28 2010
parent reply bearophile <bearophileHUGS lycos.com> writes:
Dmitry Olshansky:

 What's the problem?
As far as I know opCall is currently broken. See: http://d.puremagic.com/issues/show_bug.cgi?id=4053 http://d.puremagic.com/issues/show_bug.cgi?id=4253 Bye, bearophile
Nov 28 2010
parent kenji hara <k.hara.pg gmail.com> writes:
Today, I also encountered this bug. Non-static function should be
preferred to static function over the instance.

Kenji

2010/11/29 bearophile <bearophileHUGS lycos.com>:
 Dmitry Olshansky:

 What's the problem?
As far as I know opCall is currently broken. See: http://d.puremagic.com/issues/show_bug.cgi?id=4053 http://d.puremagic.com/issues/show_bug.cgi?id=4253 Bye, bearophile
Jan 14 2011