Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
unterminated-case.qdoc
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page qmllint-warnings-and-errors-unterminated-case.html
6\ingroup qmllint-warnings-and-errors
7
8\title Unterminated non-empty case block
9\brief [unterminated-case] A non-empty case block was not terminated.
10
11\qmllintwarningcategory unterminated-case
12
13\section1 Unterminated non-empty case block
14
15\section2 What happened?
16A case block in a switch statement was non-empty but was not terminated by a
17break, return, or throw statement. There was also no opt-in fallthrough
18comment.
19
20\section2 Why is that bad?
21Fallthrough logic in switch statements can be confusing or overlooked. If it is
22intentional, it should be marked explicitly with a comment such as
23"// fallthrough". If it isn't intentional, the warning indicates that a
24terminating statement was forgotten.
25
26\section2 Example
27\qml
28switch (state) {
29case Main.State.Reset:
30 clearState() // <--- "Unterminated non-empty case block"
31case Main.State.Invalid:
32 asyncInitState()
33 return false
34case Main.State.Initializing:
35 // wait for initialization to complete
36 return false
37case Main.State.Ready:
38 res = lookup(query)
39 log(res.stats)
40 saveToDisk(res.data) // <--- "Unterminated non-empty case block"
41default:
42 throw new InvalidStateException("Unknown state")
43}
44\endqml
45To fix this warning, add missing terminating statements or add explicit opt-in
46comments allowing fallthrough logic:
47\qml
48switch (state) {
49case Main.State.Reset:
50 clearState()
51 // fallthrough // <--- add fallthrough comment
52case Main.State.Invalid:
53 asyncInitState()
54 return false
55case Main.State.Initializing:
56 // wait for initialization to complete
57 return false
58case Main.State.Ready:
59 res = lookup(query)
60 log(res.stats)
61 saveToDisk(res.data)
62 return true // <--- add forgotten terminating statement
63default:
64 throw new InvalidStateException("Unknown state")
65}
66\endqml
67*/