www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - new X().bar(); is a syntax error?

reply Ary Manzana <ary esperanto.org.ar> writes:
Compiling:

---
class X {
	void bar() {
	}
}

void foo() {
	new X().bar();
}
---

gives me:
main.d(7): found '.' when expecting ';' following 'statement'

Is this a bug or is it the intended behaviour? I can do this in Java, 
C#, probably C++...
Sep 20 2007
parent reply BCS <ao pathlink.com> writes:
Reply to Ary,

 Compiling:
 
 ---
 class X {
 void bar() {
 }
 }
 void foo() {
 new X().bar();
 }
 ---
 
 gives me:
 main.d(7): found '.' when expecting ';' following 'statement'
 Is this a bug or is it the intended behaviour? I can do this in Java,
 C#, probably C++...
 

I think it's not parsing how you want it, try this: (new X()).bar();
Sep 20 2007
parent reply Ary Manzana <ary esperanto.org.ar> writes:
BCS escribió:
 Reply to Ary,
 
 Compiling:

 ---
 class X {
 void bar() {
 }
 }
 void foo() {
 new X().bar();
 }
 ---

 gives me:
 main.d(7): found '.' when expecting ';' following 'statement'
 Is this a bug or is it the intended behaviour? I can do this in Java,
 C#, probably C++...

I think it's not parsing how you want it, try this: (new X()).bar();

But I can do it without parenthesis in other languages... I'll try to fix this in Descent's parser and submit a bug report.
Sep 20 2007
parent Robert Fraser <fraserofthenight gmail.com> writes:
I think it might create a parsing ambiguity. Since you can refer to inner
clases by prefixing them with the name of the object or type, there's no way to
tell during the syntactic pass whether it's a qualified type name or a call
expression. You can do it in java/C# because you can't omit the trailing
parentheses at the end of the new expression, so once it hits a closing
parenthesis, the parser knows that's the end of the new expression.

Ary Manzana Wrote:

 BCS escribió:
 Reply to Ary,
 
 Compiling:

 ---
 class X {
 void bar() {
 }
 }
 void foo() {
 new X().bar();
 }
 ---

 gives me:
 main.d(7): found '.' when expecting ';' following 'statement'
 Is this a bug or is it the intended behaviour? I can do this in Java,
 C#, probably C++...

I think it's not parsing how you want it, try this: (new X()).bar();

But I can do it without parenthesis in other languages... I'll try to fix this in Descent's parser and submit a bug report.

Sep 20 2007