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\ingroup qmllint-warnings-and-errors
6
7\title Unterminated non-empty case block
8\brief [unterminated-case] A non-empty case block was not terminated.
9
10\qmllintwarningcategory unterminated-case
11
12\section1 Unterminated non-empty case block
13
14\section2 What happened?
15A case block in a switch statement was non-empty but was not terminated by a
16break, return, or throw statement. There was also no opt-in fallthrough
17comment.
18
19\section2 Why is that bad?
20Fallthrough logic in switch statements can be confusing or overlooked. If it is
21intentional, it should be marked explicitly with a comment such as
22"// fallthrough". If it isn't intentional, the warning indicates that a
23terminating statement was forgotten.
24
25\section2 Example
26\qml
27switch (state) {
28case Main.State.Reset:
29 clearState() // <--- "Unterminated non-empty case block"
30case Main.State.Invalid:
31 asyncInitState()
32 return false
33case Main.State.Initializing:
34 // wait for initialization to complete
35 return false
36case Main.State.Ready:
37 res = lookup(query)
38 log(res.stats)
39 saveToDisk(res.data) // <--- "Unterminated non-empty case block"
40default:
41 throw new InvalidStateException("Unknown state")
42}
43\endqml
44To fix this warning, add missing terminating statements or add explicit opt-in
45comments allowing fallthrough logic:
46\qml
47switch (state) {
48case Main.State.Reset:
49 clearState()
50 // fallthrough // <--- add fallthrough comment
51case Main.State.Invalid:
52 asyncInitState()
53 return false
54case Main.State.Initializing:
55 // wait for initialization to complete
56 return false
57case Main.State.Ready:
58 res = lookup(query)
59 log(res.stats)
60 saveToDisk(res.data)
61 return true // <--- add forgotten terminating statement
62default:
63 throw new InvalidStateException("Unknown state")
64}
65\endqml
66*/