Skip to content

CC0120: Suggest Case Else for Select Case statements (VB) #767

@kwhitefoot

Description

@kwhitefoot

A lot of bugs are caused by non-exhaustive matching in select statements.
If there is no Case Else one should be added that throws an exception.

Before:

Select Case A
  Case B
    DoSomething
  Case C
    DoSomethingElse
End Select

After:

Select Case A
  Case B
    DoSomething
  Case C
    DoSomethingElse
  Case Else
    Throw New Exception("Unexpected Case")
End Select

Should not raise for boolean if true and false are already handled:

Dim a = True
Select Case a
    Case True
    Case False
End Select

Diagnostic Id: CC0120
Category: Design
Severity: Warning

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions