Thread overview
new X().bar(); is a syntax error?
Sep 20, 2007
Ary Manzana
Sep 20, 2007
BCS
Sep 20, 2007
Ary Manzana
Sep 21, 2007
Robert Fraser
September 20, 2007
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++...
September 20, 2007
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();


September 20, 2007
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.
September 21, 2007
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.