Bloc de cas non vide non terminé
Cette catégorie d'avertissement est orthographiée [unterminated-case] par qmllint.
Bloc de cas non vides non terminés
Qu'est-ce qui s'est passé ?
Un bloc case dans une instruction switch était non vide mais n'était pas terminé par une instruction break, return ou throw. Il n'y avait pas non plus de commentaire d'acceptation.
Pourquoi est-ce mauvais ?
La logique de repli dans les instructions de commutation peut prêter à confusion ou être négligée. Si elle est intentionnelle, elle doit être signalée explicitement par un commentaire tel que "// fallthrough". Si ce n'est pas intentionnel, l'avertissement indique qu'une instruction de fin a été oubliée.
Exemple
switch (state) {
case Main.State.Reset:
clearState() // <--- "Unterminated non-empty case block"
case Main.State.Invalid:
asyncInitState()
return false
case Main.State.Initializing:
// wait for initialization to complete
return false
case Main.State.Ready:
res = lookup(query)
log(res.stats)
saveToDisk(res.data) // <--- "Unterminated non-empty case block"
default:
throw new InvalidStateException("Unknown state")
}Pour corriger cet avertissement, ajoutez les déclarations finales manquantes ou ajoutez des commentaires explicites autorisant la logique fallthrough :
switch (state) {
case Main.State.Reset:
clearState()
// fallthrough // <--- add fallthrough comment
case Main.State.Invalid:
asyncInitState()
return false
case Main.State.Initializing:
// wait for initialization to complete
return false
case Main.State.Ready:
res = lookup(query)
log(res.stats)
saveToDisk(res.data)
return true // <--- add forgotten terminating statement
default:
throw new InvalidStateException("Unknown state")
}© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.