aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4codegen.cpp
diff options
context:
space:
mode:
authorSami Shalayel <sami.shalayel@qt.io>2025-03-26 15:23:42 +0100
committerSami Shalayel <sami.shalayel@qt.io>2025-04-25 14:32:03 +0200
commitf8e3ad0b097de4efa7e838ac6d0ae41b133e5822 (patch)
treea6c432c5dbbe7dc4d797c0066c2d6555a3a911c3 /src/qml/compiler/qv4codegen.cpp
parentc93c7ae3548489e866d1a2115c51012597a180a5 (diff)
qmllint: warn about unreachable code
The compiler is very polite and does not tell the user about its useless code. Codegen::statementList(StatementList *ast) silently discards unreachable statements during byte code generation. Warn the user that their code is unreachable. Don't warn about function definitions because these ones are "hoisted" up, which means that their definition is supposed to be pushed up, so that they can be used even if they are behind a "return" or "throw" statement. Don't use the qqmljsbasicblock analysis for that, it reports too many "false positives" where the compiler generates dead code that can't be fixed by the user. Task-number: QTBUG-129307 Change-Id: Ia26e8af1adf4e63b26dcaa7fb10be73b7eb084d7 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
-rw-r--r--src/qml/compiler/qv4codegen.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index af63c7edf7..48807ad480 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -605,12 +605,15 @@ void Codegen::statementList(StatementList *ast)
statement(static_cast<ExpressionNode *>(it->statement));
if (it->statement == needsCompletion)
requiresReturnValue = false;
- if (it->statement->kind == Statement::Kind_ThrowStatement ||
- it->statement->kind == Statement::Kind_BreakStatement ||
- it->statement->kind == Statement::Kind_ContinueStatement ||
- it->statement->kind == Statement::Kind_ReturnStatement)
- // any code after those statements is unreachable
+ if (it->statement->kind == Statement::Kind_ThrowStatement
+ || it->statement->kind == Statement::Kind_BreakStatement
+ || it->statement->kind == Statement::Kind_ContinueStatement
+ || it->statement->kind == Statement::Kind_ReturnStatement) {
+
+ if (Visitor *visitor = _interface->unreachableVisitor())
+ Node::accept(it->next, visitor);
break;
+ }
}
requiresReturnValue = _requiresReturnValue;
insideSwitch = _insideSwitch;