Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pattern(go): ellipsis does not match cases with one-or-more case clauses #10086

Open
1 of 3 tasks
craigfe opened this issue Apr 11, 2024 · 0 comments
Open
1 of 3 tasks
Labels
bug Something isn't working priority:medium

Comments

@craigfe
Copy link

craigfe commented Apr 11, 2024

Describe the bug

The ellipsis operator cannot be used to match sequences of case clauses in a Go switch statement. For example, I'd expect the following:

switch $_ {
  case 0, ...:
    ...
}

To match the following examples:

func main() {
    // ruleid: ellipsis-in-case
    switch n {
        case 0: return
    }

    // ruleid: ellipsis-in-case
    switch n {
        case 0, 1: return
    }

    // ruleid: ellipsis-in-case
    switch n {
        case 0, 1, 2: return
    }
}

To Reproduce
https://semgrep.dev/playground/s/BY0ob

What is the priority of the bug to you?

  • P0: blocking your adoption of Semgrep or workflow
  • P1: important to fix or quite annoying
  • P2: regular bug that should get fixed

Use case
This would allow us to strengthen our Semgrep rules that attempt to catch branching on certain constants (using either switch or if). Our existing workaround is to use pattern-either to enumerate patterns for a fixed number of case clauses (e.g. 0-8).

@ievans ievans added bug Something isn't working priority:medium labels Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:medium
Development

No branches or pull requests

2 participants