Thread overview | ||||||
---|---|---|---|---|---|---|
|
September 20, 2007 new X().bar(); is a syntax error? | ||||
---|---|---|---|---|
| ||||
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 Re: new X().bar(); is a syntax error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ary Manzana | 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 Re: new X().bar(); is a syntax error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | 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 Re: new X().bar(); is a syntax error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ary Manzana | 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.
|
Copyright © 1999-2021 by the D Language Foundation