Make parentheses necessary for '(x op return y) op z' #KT-16808 Fixed

This commit is contained in:
Mikhail Glukhikh
2017-09-18 16:43:36 +03:00
committed by Mikhail Glukhikh
parent 426a54c3ab
commit e8b95b971d
4 changed files with 37 additions and 5 deletions
@@ -530,11 +530,19 @@ public class KtPsiUtil {
return false;
}
// '(x operator y)' case
if (innerExpression instanceof KtBinaryExpression &&
innerOperation != KtTokens.ELVIS &&
isKeepBinaryExpressionParenthesized((KtBinaryExpression) innerExpression)) {
return true;
if (innerExpression instanceof KtBinaryExpression) {
// '(x operator return [...]) operator ...' case
if (parentElement instanceof KtBinaryExpression) {
KtBinaryExpression innerBinary = (KtBinaryExpression) innerExpression;
if (innerBinary.getRight() instanceof KtReturnExpression) {
return true;
}
}
// '(x operator y)' case
if (innerOperation != KtTokens.ELVIS &&
isKeepBinaryExpressionParenthesized((KtBinaryExpression) innerExpression)) {
return true;
}
}
int innerPriority = getPriority(innerExpression);