fix(analyzer): scope duplicate-condition to same If/Else If chain - #437
Merged
Merged
Conversation
Fixes #432 The rule compared every If/ElseIf/While condition in a rule's flat action list against all earlier ones, flagging reachable branches (second If blocks, While conditions) as unreachable with evidence: exact. Track open blocks instead: an If pushes a chain carrying its branch conditions, an Else If compares only against the innermost chain's earlier branches, While/For blocks push a placeholder so their End stays aligned, and a disabled action is unwrapped only to detect a block opener. The registry summary/documentation/finding message now describe the actual detection and knownLimits names the nondeterministic-condition case.
Teakowa
approved these changes
Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #432 —
duplicate-conditioncompared everyIf/ElseIf/Whilecondition in a rule's flat action list against all earlier ones, so reachable branches (independentIfblocks,Whileconditions, nested/foreign chains) were reported as unreachable withevidence: exact.duplicate_condition_findingsnow tracks open blocks:Ifpushes a chain carrying its branch conditions;Else Ifreports only when it repeats an earlier branch of the innermost chain;While/Forpush a placeholder so theirEndstays aligned;disabledactions are unwrapped only to detect block openers.summary/documentation/finding message now describe the actual detection (a repeatedElse Ifwithin one chain);knownLimitsnames the nondeterministic-condition (Random *) case per the issue's non-goal.analysis paritytest asserted the buggy rule-wide comparison (>= 2findings including anIf/Whilepair); now asserts exactly the in-chainElse Iffinding.Test plan
cargo test -p wright-analyzer— 18 pass, incl. 8 new/updated duplicate-condition cases covering every acceptance criterion (independentIfs,If/Whilemixes, same-chain repeats, cross-chain isolation, nested chains, loops anddisabledblocks inside chain bodies)If(c)…Else If(c)still reports 1exactfinding on theElse Ifcargo fmt --all -- --check,cargo clippy --workspace --all-targets --all-features -D warnings,cargo test --workspace --all-targets --all-features(296 pass),git diff --checkGenerated with Devin