Inspectopedia 2025.2 Help

Non-exhaustive 'when' statements will be prohibited since 1.7

Reports a non-exhaustive when statements that will lead to compilation error since 1.7.

Motivation types:

  • Problematic/meaningless usage patterns need to be discouraged/blocked (e.g. counterintuitive behaviors)

    • Code is error-prone

  • Inconsistency in the design (things are done differently in different contexts)

Impact types:

  • Compilation. Some code that used to compile won't compile any more

    • There were cases when such code worked with no exceptions

      • Some such code could compile without any warnings

More details: KT-47709: Make when statements with enum, sealed, and Boolean subjects exhaustive by default

The quick-fix adds the missing else -> {} branch.

Example:

sealed class Base { class A : Base() class B : Base() } fun test(base: Base) { when (base) { is Base.A -> "" } }

After the quick-fix is applied:

sealed class Base { class A : Base() class B : Base() } fun test(base: Base) { when (base) { is Base.A -> "" else -> {} } }

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.

NonExhaustiveWhenStatementMigration
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 | Migration

This inspection only reports if the Kotlin language level of the project or module is 1.6 or higher.

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection NonExhaustiveWhenStatementMigration

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2025.2, Qodana for JVM 2025.2,

Last modified: 18 September 2025