Inspectopedia Help

Function should have 'operator' modifier

Reports a function that matches one of the operator conventions but lacks the operator keyword.

By adding the operator modifier, you might allow function consumers to write idiomatic Kotlin code.

Example:

class Complex(val real: Double, val imaginary: Double) { fun plus(other: Complex) = Complex(real + other.real, imaginary + other.imaginary) } fun usage(a: Complex, b: Complex) { a.plus(b) }

The quick-fix adds the operator modifier keyword:

class Complex(val real: Double, val imaginary: Double) { operator fun plus(other: Complex) = Complex(real + other.real, imaginary + other.imaginary) } fun usage(a: Complex, b: Complex) { a + b }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

AddOperatorModifier
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Kotlin | Style issues

Availability

By default bundled with

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin

Kotlin, 241.18072-IJ

Last modified: 18 June 2024