aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2020-07-01 14:49:21 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2020-07-03 10:44:59 +0200
commit89861ad24970e71ac79a296406fe0fd757139fab (patch)
treee27c447368fefc623818aa17bc17f1b2ceda1a99
parent8cf45b19d5c5c65053a1c41f6293df37947e685d (diff)
qmlformat: Fix handling of empty blocks
Empty blocks were often not handled properly. (i.e. in if, for and while blocks) Fixes: QTBUG-85321 Change-Id: I4035dd239a095814362e0aec142b387dc113f282 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit a2969b1720fc8fbd6cb84562fb62a8c02cbca84a) Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--tools/qmlformat/dumpastvisitor.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/tools/qmlformat/dumpastvisitor.cpp b/tools/qmlformat/dumpastvisitor.cpp
index 3b23ddf128..c92d25787f 100644
--- a/tools/qmlformat/dumpastvisitor.cpp
+++ b/tools/qmlformat/dumpastvisitor.cpp
@@ -597,7 +597,8 @@ bool needsSemicolon(int kind)
QString DumpAstVisitor::parseBlock(Block *block, bool hasNext, bool allowBraceless)
{
- bool hasOneLine = (block->statements == nullptr || block->statements->next == nullptr) && allowBraceless;
+ bool hasOneLine =
+ (block->statements != nullptr && block->statements->next == nullptr) && allowBraceless;
QString result = hasOneLine ? "\n" : "{\n";
m_indentLevel++;
@@ -613,6 +614,8 @@ QString DumpAstVisitor::parseBlock(Block *block, bool hasNext, bool allowBracele
if (block->statements) {
m_blockNeededBraces |= !needsSemicolon(block->statements->statement->kind)
|| (block->statements->next != nullptr);
+ } else {
+ m_blockNeededBraces = true;
}
return result;
@@ -858,6 +861,9 @@ QString DumpAstVisitor::parseStatementList(StatementList *list)
{
QString result = "";
+ if (list == nullptr)
+ return "";
+
result += getOrphanedComments(list);
for (auto *item = list; item != nullptr; item = item->next) {