| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
November 08, 2015 Why does opCall disable struct-literal syntax? | ||||
|---|---|---|---|---|
| ||||
I understand why _static_ opCall would disable it, as a static call and struct construction are syntactically similar. But it seems like instance opCall and struct literal construction should be unambiguous:
struct S { int i; void opCall(int i) { } }
S s = S(3); // clearly a constructor
s(3); // clearly opCall
Is this just a technical limitation, or is there some other reasoning?
See (http://dlang.org/operatoroverloading.html#function-call).
| ||||
November 08, 2015 Re: Why does opCall disable struct-literal syntax? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to rcorre | On Sunday, 8 November 2015 at 23:26:44 UTC, rcorre wrote:
> Is this just a technical limitation, or is there some other reasoning?
Old bug/misdesign inherited from old D before there were struct constructors. It really should be the rest of the way fixed, but non-static and static methods, including opCall, are still not properly distinguished by the D language.
Type.staticFunction(); // compiles, used to be done to kinda mimic constructors before they were there
obj.staticFunction(); // also compiles, which means a change at this point would be a breaking change
| |||
November 09, 2015 Re: Why does opCall disable struct-literal syntax? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Sunday, 8 November 2015 at 23:54:52 UTC, Adam D. Ruppe wrote:
> On Sunday, 8 November 2015 at 23:26:44 UTC, rcorre wrote:
>> Is this just a technical limitation, or is there some other reasoning?
>
> Old bug/misdesign inherited from old D before there were struct constructors. It really should be the rest of the way fixed, but non-static and static methods, including opCall, are still not properly distinguished by the D language.
>
> Type.staticFunction(); // compiles, used to be done to kinda mimic constructors before they were there
>
> obj.staticFunction(); // also compiles, which means a change at this point would be a breaking change
That seems like the opposite of what's happening here. It's not a static member being invoked on an instance, but an instance member being invoked on the type.
Type.memberFunction() should never be possible, right?
| |||
November 09, 2015 Re: Why does opCall disable struct-literal syntax? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to rcorre | On Monday, 9 November 2015 at 02:43:06 UTC, rcorre wrote:
> On Sunday, 8 November 2015 at 23:54:52 UTC, Adam D. Ruppe wrote:
>> On Sunday, 8 November 2015 at 23:26:44 UTC, rcorre wrote:
>>> Is this just a technical limitation, or is there some other reasoning?
>>
>> Old bug/misdesign inherited from old D before there were struct constructors. It really should be the rest of the way fixed, but non-static and static methods, including opCall, are still not properly distinguished by the D language.
>>
>> Type.staticFunction(); // compiles, used to be done to kinda mimic constructors before they were there
>>
>> obj.staticFunction(); // also compiles, which means a change at this point would be a breaking change
>
> That seems like the opposite of what's happening here. It's not a static member being invoked on an instance, but an instance member being invoked on the type.
>
> Type.memberFunction() should never be possible, right?
Oh, I think I see the confusion. If you _were_ to define static opCall, it could also be used on an instance. Which makes distinguishing the two ... problematic. Weird.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply