On Tue, 30 Aug 2011 11:58:20 -0400, Steven Schveighoffer <schvei...@yahoo.com> wrote:

On Tue, 30 Aug 2011 11:38:54 -0400, Andrei Alexandrescu <seewebsiteforem...@erdani.org> wrote:

On 8/30/11 7:34 AM, Steven Schveighoffer wrote:
We don't have as big a problem in D due to introspection. I fear, however, that we'll need to add static if (...) obj.method(); else typeof(obj).method();

I don't see an improvement.

In terms of generic programming, you have a good point. I don't see a good way around this without altering syntax.

Perhaps we could do something like this (a la recently added @disable this):

struct File
{
    static File open(string fname);

    @disable open; // disable calling from an instance
}

Yuck...  nevermind :)

Hm... this might be workable. Disallow calling static method from instance unless requested by the author:

struct S1
{
   static void foo();
}

struct S2
{
   static void foo();
   alias foo this.foo;
}

S1 s1;
S2 s2;

s1.foo(); // error
s2.foo(); // ok

-Steve

Reply via email to