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

default is redundant when switch is exhaustive #45437

Closed
srawlins opened this issue Mar 23, 2021 · 2 comments
Closed

default is redundant when switch is exhaustive #45437

srawlins opened this issue Mar 23, 2021 · 2 comments
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@srawlins
Copy link
Member

analyzer Hint implementation issue for dart-lang/language#1539

Given:

enum Level {
  low,
  medium,
  high
}

String myFunction(Level level) {
  switch (level) {
    case Level.low:
      return 'low';
    case Level.medium:
      return 'medium';
    case Level.high:
      return 'high';
    default:
      return 'never be executed';  // 'switch' is exhaustive so 'default' is redundant here
  }
}

Show a warning that default is dead code. I suspect this would use our current dead_code mechanisms and/or flow analysis.

@srawlins srawlins added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-warning Issues with the analyzer's Warning codes labels Mar 23, 2021
@srawlins srawlins added the P3 A lower priority bug or feature request label Mar 23, 2021
@srawlins srawlins added the type-enhancement A request for a change that isn't a bug label Mar 24, 2022
@srawlins srawlins added the contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) label May 20, 2022
@shilangyu
Copy link
Contributor

I would like to give this a try. Any pointers as to which packages this affects would be appreciated. I can probably figure out the rest.

@parlough
Copy link
Member

parlough commented Oct 8, 2024

Closing as a duplicate of #54575 and resolved by cda2815.

#54575 has many more linked commits that worked towards resolving this across the ecosystem.

@parlough parlough closed this as completed Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants