Inspectopedia Help

Irregular usage of 'iota'

Reports irregular usage of iota within a constant declaration.

The iota identifier is reset for every constant declaration and automatically incremented for every constant specification. Within one constant specification, the identifier keeps its value. Explicitly referring to iota does not reset the counter.

For details, see Iota in the Go specification.

This inspection is triggered if two constant specifications have a textually identical expression list containing at least one reference to iota and there are exclusively constant specifications without an expression list in between them.

Consider omitting the redundant expression list or writing out the expression list every time.


const ( a = iota // 0 b // 1 c = iota // 2 )

Triggers the inspection as the iota in the definition of c is redundant.


const ( a, aa = iota, iota // 0, 0 b, bb // 1, 1 c, cc = iota + 40, iota // 42, 2 )

Does not trigger the inspection as none of the expression lists is redundant.

Inspection Details

Available in:

GoLand 2023.3



Last modified: 13 July 2023