www.digitalmars.com         C & C++   DMDScript  

D - opCall bug

reply Mik Mifflin <mik42 NOadelphiaSPAM.net> writes:
The following program doesn't compile:
class caller {
   caller opCall (out int i) {
      i = 10;
      return this;
   }
}

void main (char[][] args) {
   caller c = new caller;
   int x,y;
   c(x)(y);
}

It gives this error:
opcall.d(11): declaration main.x is already defined

Compiler bug?  Or did I do something stupid?

-- 
 - Mik Mifflin
Feb 19 2004
next sibling parent reply Andrew <Andrew_member pathlink.com> writes:
In article <c133a2$1cun$1 digitaldaemon.com>, Mik Mifflin says...

void main (char[][] args) {
   caller c = new caller;
   int x,y;
   c(x)(y);    <<----:
}                    |
| HERE I don't think you can chain a function or opCall in that manner... The following works fine... void main (char[][] args) { caller c = new caller; int x,y; c(x); c(y); }
Feb 19 2004
next sibling parent reply "davepermen" <davepermen hotmail.com> writes:
you should be able to do that. done similar things yet..

i'll have a closer look... uhm.. tomorrow..

"Andrew" <Andrew_member pathlink.com> schrieb im Newsbeitrag
news:c13739$1jlt$1 digitaldaemon.com...
 In article <c133a2$1cun$1 digitaldaemon.com>, Mik Mifflin says...

void main (char[][] args) {
   caller c = new caller;
   int x,y;
   c(x)(y);    <<----:
}                    |
| HERE I don't think you can chain a function or opCall in that manner... The following works fine... void main (char[][] args) { caller c = new caller; int x,y; c(x); c(y); }
Feb 19 2004
parent reply Andrew <Andrew_member pathlink.com> writes:
In article <c138s9$1n7c$1 digitaldaemon.com>, davepermen says...
you should be able to do that. done similar things yet..

i'll have a closer look... uhm.. tomorrow..
IC. Could you please explain some of the advantages and disadvantages of doing things this way? Other than being able to simultaneously assign a value to multiple variables, what are some other uses for this feature? Thanks, Andrew
Feb 20 2004
parent reply Mik Mifflin <mik42 NOadelphiaSPAM.net> writes:
Andrew wrote:

 In article <c138s9$1n7c$1 digitaldaemon.com>, davepermen says...
you should be able to do that. done similar things yet..

i'll have a closer look... uhm.. tomorrow..
IC. Could you please explain some of the advantages and disadvantages of doing things this way? Other than being able to simultaneously assign a value to multiple variables, what are some other uses for this feature? Thanks, Andrew
I don't think the point is if anyone actually has a use for it, the point is that it should work, and does not. -- - Mik Mifflin
Feb 20 2004
parent Andrew <Andrew_member pathlink.com> writes:
In article <c15bp3$2k3l$1 digitaldaemon.com>, Mik Mifflin says...
Andrew wrote:

 In article <c138s9$1n7c$1 digitaldaemon.com>, davepermen says...
you should be able to do that. done similar things yet..

i'll have a closer look... uhm.. tomorrow..
IC. Could you please explain some of the advantages and disadvantages of doing things this way? Other than being able to simultaneously assign a value to multiple variables, what are some other uses for this feature? Thanks, Andrew
I don't think the point is if anyone actually has a use for it, the point is that it should work, and does not. -- - Mik Mifflin
I completely understand that Mik. I simply wanted to expand my knowledge. Thanks anyhow. Andrew
Feb 20 2004
prev sibling next sibling parent Mik Mifflin <mik42 NOadelphiaSPAM.net> writes:
Andrew wrote:

 In article <c133a2$1cun$1 digitaldaemon.com>, Mik Mifflin says...
 
void main (char[][] args) {
   caller c = new caller;
   int x,y;
   c(x)(y);    <<----:
}                    |
| HERE I don't think you can chain a function or opCall in that manner... The following works fine... void main (char[][] args) { caller c = new caller; int x,y; c(x); c(y); }
I can in this instance, as I return a caller object. -- - Mik Mifflin
Feb 19 2004
prev sibling parent Manfred Nowak <svv1999 hotmail.com> writes:
Andrew wrote:

[...]
 The following works fine...
[...] However, a very misleading error message. So long.
Feb 19 2004
prev sibling parent reply Mik Mifflin <mik42 NOadelphiaSPAM.net> writes:
Mik Mifflin wrote:

 The following program doesn't compile:
 class caller {
    caller opCall (out int i) {
       i = 10;
       return this;
    }
 }
 
 void main (char[][] args) {
    caller c = new caller;
    int x,y;
    c(x)(y);
 }
 
 It gives this error:
 opcall.d(11): declaration main.x is already defined
 
 Compiler bug?  Or did I do something stupid?
 
A temporary workaround is '(c(x)(y))', with the extra parentheses. The error goes away and it works as expected.. -- - Mik Mifflin
Feb 19 2004
parent Manfred Nowak <svv1999 hotmail.com> writes:
Mik Mifflin wrote:

 A temporary workaround is '(c(x)(y))', with the extra parentheses.  The
 error goes away and it works as expected..
This is a cool thing. I am searching for something like that in the thread `[experts] opComma'. `cast(void) c(x)(y)' also works. So long.
Feb 19 2004