Suggestion: Change precedence of 'new'

Georg Wrede georg at nospam.org
Thu Apr 10 08:49:14 PDT 2008


Bill Baxter wrote:
> Robert Fraser wrote:
> 
>> Unknown W. Brackets wrote:
>>
>>> I think the problem is in supporting this syntax:
>>>
>>> auto x = new package.module.Class;
>>
>>
>> The argument (as far as I can tell) is that it would be supported only 
>> if trailing parentheses were supplied, so that expression would have 
>> to be written as "new package.module.Class().propertyMethod;".
> 
> 
> That makes sense.  So the rule would be that 'new' munches all the 
> dot-separated identifiers to its right till it hits something besides a 
> dot or an identifier.
> 
> Here's another one from actual D code ported from Java:
> 
>     (new class Runnable {
>         public void run() {
>             if (canvas.isDisposed()) return;
>             render();
>             canvas.swapBuffers();
>             canvas.getDisplay().timerExec(15, this);
>         }
>     }).run();
> 
> In Java the parens around that whole mess aren't necessary.

Just to clarify, how would that look with the proposed precedence?



More information about the Digitalmars-d mailing list