Commit d8427157 authored by Christian Kamm's avatar Christian Kamm
Browse files

Quickfix: Disallow semantically invalid splits of if statements.

parent dd71d9a5
...@@ -671,6 +671,7 @@ public: ...@@ -671,6 +671,7 @@ public:
if (! pattern) if (! pattern)
return -1; return -1;
unsigned splitKind = 0;
for (++index; index < path.size(); ++index) { for (++index; index < path.size(); ++index) {
AST *node = path.at(index); AST *node = path.at(index);
condition = node->asBinaryExpression(); condition = node->asBinaryExpression();
...@@ -678,12 +679,21 @@ public: ...@@ -678,12 +679,21 @@ public:
return -1; return -1;
Token binaryToken = tokenAt(condition->binary_op_token); Token binaryToken = tokenAt(condition->binary_op_token);
if (binaryToken.is(T_AMPER_AMPER) || binaryToken.is(T_PIPE_PIPE)) {
if (isCursorOn(condition->binary_op_token)) // only accept a chain of ||s or &&s - no mixing
return index; if (! splitKind) {
} else { splitKind = binaryToken.kind();
if (splitKind != T_AMPER_AMPER && splitKind != T_PIPE_PIPE)
return -1;
// we can't reliably split &&s in ifs with an else branch
if (splitKind == T_AMPER_AMPER && pattern->else_statement)
return -1;
} else if (splitKind != binaryToken.kind()) {
return -1; return -1;
} }
if (isCursorOn(condition->binary_op_token))
return index;
} }
return -1; return -1;
...@@ -719,7 +729,7 @@ public: ...@@ -719,7 +729,7 @@ public:
setTopLevelNode(pattern); setTopLevelNode(pattern);
int insertPos = endOf(pattern); int insertPos = endOf(ifTrueStatement);
if (compoundStatement) if (compoundStatement)
insert(insertPos, QLatin1String(" ")); insert(insertPos, QLatin1String(" "));
else else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment