このページでは

紛らわしいプラス

この警告カテゴリのスペルは[confusing-pluses] です。

混乱を招くプラス

何が起こったのか?

JavaScript のコードが '+' で書かれた演算子の組み合わせを混乱した方法で使用しています。隣接する '+' 演算子を区別するのは難しいかもしれません。これは、型にはまった間隔によって悪化する可能性があります。

なぜ悪いのか?

コードが読みにくくなり、混乱を招く可能性があります。

import QtQuick

Item {
    function f(a: int, b: int) {
        let x = a++ + b
        let y = a + +b
        let z = a + ++b
        return x + y + z
    }
}

この警告を修正するには、似たような'+'演算子が隣り合わないようにコードを書き直す。可能な限り式を単純化する。冗長な単項演算子や空白を削除し、括弧を使って部分式を分離する。

これらの演算子は強制演算を行う可能性があることに注意してください。a + +b のような式は、b の型によってはa + b と等価ではないかもしれない。

import QtQuick

Item {
    function f(a: int, b: int) {
        let x = (a++) + b
        let y = a + b
        let z = a + b + 1
        return x + y + z
    }
}

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