Static method conflicts with non-static method?
Steven Schveighoffer
schveiguy at yahoo.com
Fri Apr 27 04:51:40 PDT 2012
On Fri, 27 Apr 2012 07:31:50 -0400, so <so at so.so> wrote:
> On Friday, 27 April 2012 at 11:23:39 UTC, Steven Schveighoffer wrote:
>> On Fri, 27 Apr 2012 07:03:02 -0400, so <so at so.so> wrote:
>>
>>> On Friday, 27 April 2012 at 10:48:29 UTC, Steven Schveighoffer wrote:
>>>
>>>> With the advent of UFCS, this argument has much less teeth. Maybe it
>>>> should be revisited...
>>>>
>>>> -Steve
>>>
>>> Elaborate please how UFCS would help in that context.
>>
>> Hm... thinking about it, UFCS requires passing the instance, while
>> static methods do not. So it doesn't make as much sense as I thought...
>>
>> I still think static methods should not be callable on instances
>> without opt-in from the aggregate author. The confusion it can cause
>> is not worth the benefits IMO.
>
> I agree it is ugly. If there is a way out (reason why i asked), we
> should just dump it.
The idea I came up with in my proposal
(http://d.puremagic.com/issues/show_bug.cgi?id=6579) was to allow aliasing
the static method into the instance namespace:
struct S1
{
static void foo() {}
alias S1.foo this.foo;
}
struct S2
{
static void foo() {}
}
void main()
{
S1 i1;
S2 i2;
S1.foo(); // ok
i1.foo(); // ok
S2.foo(); // ok
i2.foo(); // error
}
-Steve
More information about the Digitalmars-d
mailing list