-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent adjacent unary operators from merging #328
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1075,19 +1075,33 @@ class KotlinInputAstVisitor( | |
builder.close() | ||
} | ||
|
||
override fun visitUnaryExpression(expression: KtUnaryExpression) { | ||
override fun visitPostfixExpression(expression: KtPostfixExpression) { | ||
builder.sync(expression) | ||
builder.block(ZERO) { | ||
visit(expression.baseExpression) | ||
builder.token(expression.operationReference.text) | ||
val baseExpression = expression.baseExpression | ||
val operator = expression.operationReference.text | ||
|
||
visit(baseExpression) | ||
if (baseExpression is KtPostfixExpression && | ||
baseExpression.operationReference.text.last() == operator.first()) { | ||
builder.space() | ||
} | ||
builder.token(operator) | ||
} | ||
} | ||
|
||
override fun visitPrefixExpression(expression: KtPrefixExpression) { | ||
builder.sync(expression) | ||
builder.block(ZERO) { | ||
builder.token(expression.operationReference.text) | ||
visit(expression.baseExpression) | ||
val baseExpression = expression.baseExpression | ||
val operator = expression.operationReference.text | ||
|
||
builder.token(operator) | ||
if (baseExpression is KtPrefixExpression && | ||
operator.last() == baseExpression.operationReference.text.first()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this relies on the fact that there are no operators with a mixture of characters, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That might be better? I like not guessing. How do you feel about these cases:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hate Kotlin :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
builder.space() | ||
} | ||
visit(baseExpression) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this exercised in any test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not currently. The only example I can think of would be
a!! !!
, buta!!!!
has the same semantics. Do you have a preference on that case?