Skip to content

Files

Latest commit

 

History

History
33 lines (23 loc) · 735 Bytes

DuplicateCaseInWhenExpression.md

File metadata and controls

33 lines (23 loc) · 735 Bytes

Pattern: Duplicate case in when expression

Issue: -

Description

Flags duplicate case statements in when expressions.

If a when expression contains the same case statement multiple times they should be merged. Otherwise it might be easy to miss one of the cases when reading the code, leading to unwanted side effects.

Example of incorrect code:

when (i) {
    1 -> println("one")
    1 -> println("one")
    else -> println("else")
}

Example of correct code:

when (i) {
    1 -> println("one")
    else -> println("else")
}

Further Reading