cadence-tools icon indicating copy to clipboard operation
cadence-tools copied to clipboard

[Lint] Reject duplicate cases in switch-statement

Open SupunS opened this issue 4 years ago • 2 comments

Issue To Be Solved

Currently, duplicate cases are allowed in switch-statement. That can leave unreachable codes without the user being aware.

e.g.:

pub fun test(s: String) {
    switch s {
        case "foo":
            return 1
        case "bar":
            return 2
        case "bar":    // a duplicate case: no errors/warnings are reported
            return 3
    }
}

Suggest A Solution

Validate and reject duplicate cases during compile time.

SupunS avatar Jan 15 '21 05:01 SupunS

is it safe to assume this ticket as done? )

nozim avatar Jul 10 '23 14:07 nozim

The implementation is available in this [closed] PR: https://github.com/onflow/cadence-tools/pull/8. But unfortunately, it was never merged, because of some tech-dept at the time, where these tools were moved to a separate repo.

We would still need to resurface that PR/changes, and open it as a new PR.

SupunS avatar Jul 10 '23 14:07 SupunS