Inspectopedia
 
2024.3

Missing 'case' statements for 'iota' consts in 'switch'

Warning
Reliability
New
Last modified: 03 December 2024

Reports unhandled values in switch statements when the iota identifier is in the const declaration. To handle these values, consider using case or default clauses.

The iota keyword in Go creates a sequence of integers in a const block. Although the Go compiler does not require handling all iota values, missing some of them could indicate a bug.

For more information about iota, refer to Iota at go.dev.

Examples:

The IDE triggers an inspection because c is not handled by the switch statement. Note that c is in the same const block even if it does not use iota.

Quick-fix options are Create 'case' clause for values and Create 'default' clause. After the Create 'default' clause quick-fix is applied: