終了していない空でないケースブロック

この警告カテゴリーはqmllintによって[unterminated-case]

終了した空でないケースブロック

何が起こったのか?

switch文のcaseブロックが空ではないが、break文、return文、throw文で終了していない。また、オプトインのフォールスルー・コメントもありませんでした。

なぜ悪いのですか?

switch文のフォールスルー・ロジックは、混乱を招いたり、見落とされたりすることがあります。意図的なものであれば、"// fallthrough "のようなコメントで明示する必要があります。意図的でない場合、警告は終了文が忘れられていることを示しています。

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")
}

この警告を修正するには、抜けている終端ステートメントを追加するか、フォールスルー・ロジックを許可する明示的なオプトイン・コメントを追加する:

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")
}

© 2025 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.