QmlJS: Fix checking for case and default blocks

case and default blocks inside a switch statement are just
special statement lists which need proper handling to avoid
wrong warnings regarding using standalone blocks.

Task-number: QTCREATORBUG-24214
Change-Id: Ia682b13ed4df21c5831308193d5abaf5163bde59
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Christian Stenger
2021-05-04 11:15:05 +02:00
parent a86da031c7
commit 845afb25fc
2 changed files with 12 additions and 0 deletions

View File

@@ -1366,6 +1366,7 @@ bool Check::visit(Block *ast)
&& !cast<WhileStatement *>(p)
&& !cast<IfStatement *>(p)
&& !cast<SwitchStatement *>(p)
&& !isCaseOrDefault(p)
&& !cast<WithStatement *>(p)) {
addMessage(WarnBlock, ast->lbraceToken);
}
@@ -1656,6 +1657,15 @@ bool Check::isQtQuick2Ui() const
return _doc->language() == Dialect::QmlQtQuick2Ui;
}
bool Check::isCaseOrDefault(Node *n)
{
if (!cast<StatementList *>(n))
return false;
if (Node *p = parent(1))
return p->kind == Node::Kind_CaseClause || p->kind == Node::Kind_DefaultClause;
return false;
}
bool Check::visit(NewExpression *ast)
{
checkNewExpression(ast->expression);