Skip to content

unnecessary_breaks fails to report an unnecessary break inside a default clause #59512

Closed
@stereotype441

Description

@stereotype441

Describe the issue
Currently, the unnecessary_breaks lint only reports for break statements that appear after a case clause. If the break statement appears at the end of a default clause, no lint is reported.

To Reproduce

main(List<String> args) {
  switch (args.length) {
    case 1:
      print('1 arg');
    default:
      print('${args.length} args');
      break; // No lint reported
  }
}

Expected behavior
A lint should be reported at the line marked No lint reported above.

Additional context
Note that in the above example, if default: is changed to case _:, the lint works properly.

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work ondevexp-linterIssues with the analyzer's support for the linter packagelegacy-area-analyzerUse area-devexp instead.linter-false-negativetype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions