www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - opCall/ctor partially sorted out

reply "bearophile" <bearophileHUGS lycos.com> writes:
Recently one of the most important bugs was mostly fixed, beside 
Win64 support this is one of the most important changes in dmd 
2.061:

http://d.puremagic.com/issues/show_bug.cgi?id=6036


Do you think this has to be correct code?

struct Adder {
     int v;
     int opCall(int x) { return x + v; }
}
void main() {
     auto a = Adder(5);
}

Bye,
bearophile
Oct 06 2012
next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Sunday, October 07, 2012 04:24:33 bearophile wrote:
 Recently one of the most important bugs was mostly fixed, beside
 Win64 support this is one of the most important changes in dmd
 2.061:
 
 http://d.puremagic.com/issues/show_bug.cgi?id=6036
 
 
 Do you think this has to be correct code?
 
 struct Adder {
      int v;
      int opCall(int x) { return x + v; }
 }
 void main() {
      auto a = Adder(5);
 }
I would argue that that should compile, but it wouldn't surprise me at all if it doesn't - especially because of the stupidity that makes it so that you can call static functions with member instances, muddying the differences between static and non-static in terms of how you call them. And the fact that you can't overload a function as static and non-static (probably due to the aforementioned nonsense) just makes it worse. So, much as this _should_ work IMHO, it doesn't surprise me at all if it doesn't. - Jonathan M Davis
Oct 06 2012
prev sibling next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Sunday, 7 October 2012 at 02:36:31 UTC, bearophile wrote:
 Do you think this has to be correct code?
I think it should work, but I'd call it a minor bug if it doesn't because it isn't hard to work around.
Oct 06 2012
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 10/7/12, bearophile <bearophileHUGS lycos.com> wrote:
 Do you think this has to be correct code?

 struct Adder {
      int v;
      int opCall(int x) { return x + v; }
 }
 void main() {
      auto a = Adder(5);
 }
opCall isn't static so there's no ambiguity here imo.
Oct 06 2012
prev sibling next sibling parent Artur Skawina <art.08.09 gmail.com> writes:
On 10/07/12 04:24, bearophile wrote:
 Recently one of the most important bugs was mostly fixed, beside Win64 support
this is one of the most important changes in dmd 2.061:
 
 http://d.puremagic.com/issues/show_bug.cgi?id=6036
 
 
 Do you think this has to be correct code?
 
 struct Adder {
     int v;
     int opCall(int x) { return x + v; }
 }
 void main() {
     auto a = Adder(5);
 }
Yes, with resulting a.v==5. This should result in an int == 42: auto a = Adder(37)(5); 'static' either needs to be handled properly or another op needs to be introduced - opStaticCall(). Which might look like a hack, but doing it like that may be simpler to implement and relatively harmless (as the aggregate.op* namespace has to be treated as reserved in practice). Also, the type and instance methods shouldn't form an overload set, so separating them is a good idea (a matching non-static opCall must always take precedence). Calling the static-opCall (either opStaticCall or the "normal" 'static opCall', if/when that one works properly) with an instance should work. (not doing this would need changes to how the null-checking is done and likely cause other problems that i can't think of right now) artur
Oct 07 2012
prev sibling next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
 Recently one of the most important bugs was mostly fixed, 
 beside Win64 support this is one of the most important changes 
 in dmd 2.061:

 http://d.puremagic.com/issues/show_bug.cgi?id=6036
Next important bug to focus on is (in my top5 bug list): http://d.puremagic.com/issues/show_bug.cgi?id=3789 Bye, bearophile
Oct 07 2012
prev sibling parent deadalnix <deadalnix gmail.com> writes:
Le 07/10/2012 04:24, bearophile a écrit :
 Recently one of the most important bugs was mostly fixed, beside Win64
 support this is one of the most important changes in dmd 2.061:

 http://d.puremagic.com/issues/show_bug.cgi?id=6036


 Do you think this has to be correct code?

 struct Adder {
 int v;
 int opCall(int x) { return x + v; }
 }
 void main() {
 auto a = Adder(5);
 }

 Bye,
 bearophile
opCall isn't static here. So it shouldn't be involved.
Oct 07 2012