BSL052 — There are identical sub-expressions to the left and to the right of the "foo" operator¶
Summary¶
There are identical sub-expressions to the left and to the right of the "foo" operator
Identifiers¶
| Field | Value |
|---|---|
| Rule code | BSL052 |
| Compatible alias | IdenticalExpressions |
| Severity | WARNING |
| Enabled by default | Yes |
| Implemented | Yes |
| Tags | suspicious, logic |
Behavior¶
- The public identifier
BSL052and aliasIdenticalExpressionsare stable. - The rule reports the cases documented on this page.
- Suppressions and project configuration are applied before publication.
- The rule requires neither an external analyzer nor network access.
Configuration and suppression¶
BSL### is the primary stable identifier. The compatible alias is accepted
in select, ignore, and compatible block suppression comments.
All three suppression families support both a current line and a range. When an opening comment follows code, it affects only that line. Use any one form:
noqa:
bsl-disable:
- compatible
BSLLSform:
When the same opening comment is on a line by itself, it starts a range. Close it with the matching marker from the same family:
// noqa: BSL052
// code without this diagnostic
// noqa-enable: BSL052
// bsl-disable: BSL052
// code without this diagnostic
// bsl-enable: BSL052
// BSLLS:IdenticalExpressions-off
// code without this diagnostic
// BSLLS:IdenticalExpressions-on
To disable the rule until the end of the file, omit the closing
noqa-enable, bsl-enable, or BSLLS:…-on marker.
Opening and closing markers must belong to the same family.
Description¶
The analyzer found a code fragment that most probably has a logic error. There is an operator (, <=, >=, =, <>, AND, OR, -, /) in the program text to the left and to the right of which there are identical subexpressions.
Examples¶
In this case, the AND operator is surrounded by identical subexpressions Summ <> 0 and it allows us to detect an error made through inattention. The correct code that will not look suspicious to the analyzer looks in the following way:
OR