forked from qt-creator/qt-creator
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:
@@ -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);
|
||||
|
Reference in New Issue
Block a user