eclipse-archived / ceylon.formatter

A formatter for the Ceylon programming language, written in Ceylon.
Apache License 2.0
14 stars 11 forks source link

Variables without SpecifierExpressions #27

Closed lucaswerkmeister closed 10 years ago

lucaswerkmeister commented 10 years ago

In

if (exists myVar) { ... }

the ExistsCondition has a Variable with mainToken myVar, and also a specifierExpression (what would normally be = someExpression.fooBar) that boils down to the Identifier myVar as well. That is to say, the token myVar is used twice in the AST; this is currently not expected and thus leads to every subsequent token being unexpected, each with a huge stacktrace. Lovely.

(The test only tests if(exists c =test.first) { ... }, which works because there’s an actual SpecifierExpression.)

lucaswerkmeister commented 10 years ago

Note to future, potentially confused self: This should not be fixed in the FormattingWriter – e. g., by detecting “we’re already past this token, ignore it” – but must be fixed in the Visitor: a solution in the FormattingWriter wouldn’t work in the case of no TokenStream (see #17).

(Past token detection might still be useful for diagnostics though.)

lucaswerkmeister commented 10 years ago

this is currently not expected and thus leads to every subsequent token being unexpected, each with a huge stacktrace.

Actually, that’s not true. The token is not written, handleException is called, and then the visit continues normally (handleException only prints a stacktrace). Since no token was fast-forwarded over, the rest of the formatting process can continue normally.

That’s actually bad for automated testing...