A when condition repeats an earlier one, so its branch never runs for that value

tx0/kotlin:duplicate-when-conditiondefaultwarningreliability/control-flowdepth fastbug

What it finds

when (code) { 1 -> a(); 2 -> b(); 1 -> c() }: the second 1 can never be chosen, as the first entry takes it. Usually one value was meant to be different. Conditions that call functions are left alone.

From the rule's source, duplicate_when_condition.rs.

Example from the rule's tests
fun describe(code: Int, x: Any): String = when (code) {    1 -> "one"    2, 3 -> "few"    1 -> "again"tx0 reports: the condition 1 repeats an earlier entry    in 4..9 -> "some"    else -> when (x) {        is String -> "string"        is String -> "twice"tx0 reports: the condition is String repeats        else -> "other"    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:duplicate-when-condition" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/kotlin:duplicate-when-condition] reason="..."

tx0 explain tx0/kotlin:duplicate-when-condition shows the same in the terminal. Found a false positive? Report it.