D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2945 - Precedence of 'new' vs '.'
Summary: Precedence of 'new' vs '.'
Status: RESOLVED DUPLICATE of issue 8635
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-05 19:00 UTC by Frank Benoit
Modified: 2014-04-18 09:12 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Frank Benoit 2009-05-05 19:00:30 UTC
In Java one can write:

new MyClass().run();

in D this does not compile, parenthesis are needed.

(new MyClass()).run();

I think this should behave like Java.
See also http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=89433
Comment 1 Matti Niemenmaa 2009-05-06 04:50:59 UTC
There might be a problem here in that in D you can write it without the brackets:

new MyClass.Foo;

Is the above trying to create a new Myclass.Foo or is it trying to create a new MyClass and then access its Foo member? It depends on the type of Foo, and such a dependency is, I think, what Walter has been trying to avoid.

Nevertheless, I often forget the brackets myself and wouldn't mind this change, I just think the above means that it's not going to happen.
Comment 2 Simen Kjaeraas 2009-05-06 07:53:20 UTC
(In reply to comment #1)
> There might be a problem here in that in D you can write it without the
> brackets:
> 
> new MyClass.Foo;
> 
> Is the above trying to create a new Myclass.Foo or is it trying to create a new
> MyClass and then access its Foo member? It depends on the type of Foo, and such
> a dependency is, I think, what Walter has been trying to avoid.
> 
> Nevertheless, I often forget the brackets myself and wouldn't mind this change,
> I just think the above means that it's not going to happen.
> 

Ceraintly. However, new MyClass().Foo; has no such ambiguity until D becomes capable of returning types from functions.

--
  Simen
Comment 3 Steven Schveighoffer 2009-05-06 09:05:27 UTC
(In reply to comment #2)
> Ceraintly. However, new MyClass().Foo; has no such ambiguity until D becomes
> capable of returning types from functions.

Traditionally, runtime reflection like that is done by calling methods on the returned type, not by using a compile-time operator.

So it would look more like:

MyClass.Foo.instantiate();
Comment 4 Andrej Mitrovic 2013-01-11 19:44:14 UTC

*** This issue has been marked as a duplicate of issue 8635 ***