| Thread overview | |||||||||
|---|---|---|---|---|---|---|---|---|---|
|
October 07, 2012 opCall/ctor partially sorted out | ||||
|---|---|---|---|---|
| ||||
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 | ||||
October 07, 2012 Re: opCall/ctor partially sorted out | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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
| |||
October 07, 2012 Re: opCall/ctor partially sorted out | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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.
| |||
October 07, 2012 Re: opCall/ctor partially sorted out | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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.
| |||
October 07, 2012 Re: opCall/ctor partially sorted out | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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
| |||
October 07, 2012 Re: opCall/ctor partially sorted out | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | > 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 | |||
October 07, 2012 Re: opCall/ctor partially sorted out | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply