diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2020-07-01 14:49:21 +0200 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2020-07-02 13:47:15 +0200 |
commit | a2969b1720fc8fbd6cb84562fb62a8c02cbca84a (patch) | |
tree | a6250d61c800eaa95aa03e417509ea32029d8222 /tools | |
parent | 9df9059a4b88676c7352db92391de2c268550fc0 (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
Pick-to: 5.15
Change-Id: I4035dd239a095814362e0aec142b387dc113f282
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qmlformat/dumpastvisitor.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/tools/qmlformat/dumpastvisitor.cpp b/tools/qmlformat/dumpastvisitor.cpp index 57a1ea9fcb..2b7b1c7c2f 100644 --- a/tools/qmlformat/dumpastvisitor.cpp +++ b/tools/qmlformat/dumpastvisitor.cpp @@ -603,7 +603,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++; @@ -619,6 +620,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; @@ -864,6 +867,9 @@ QString DumpAstVisitor::parseStatementList(StatementList *list) { QString result = ""; + if (list == nullptr) + return ""; + result += getOrphanedComments(list); for (auto *item = list; item != nullptr; item = item->next) { |