Kotlin Help

Compatibility guide for Kotlin 1.7

Keeping the Language Modern and Comfortable Updates are among the fundamental principles in Kotlin Language Design. The former says that constructs which obstruct language evolution should be removed, and the latter says that this removal should be well-communicated beforehand to make code migration as smooth as possible.

While most of the language changes were already announced through other channels, like update changelogs or compiler warnings, this document summarizes them all, providing a complete reference for migration from Kotlin 1.6 to Kotlin 1.7.

Basic terms

In this document we introduce several kinds of compatibility:

  • source: source-incompatible change stops code that used to compile fine (without errors or warnings) from compiling anymore

  • binary: two binary artifacts are said to be binary-compatible if interchanging them doesn't lead to loading or linkage errors

  • behavioral: a change is said to be behavioral-incompatible if the same program demonstrates different behavior before and after applying the change

Remember that those definitions are given only for pure Kotlin. Compatibility of Kotlin code from the other languages perspective (for example, from Java) is out of the scope of this document.

Language

Make safe call result always nullable

Prohibit the delegation of super calls to an abstract superclass member

Prohibit exposing non-public types through public properties declared in a non-public primary constructor

Prohibit access to uninitialized enum entries qualified with the enum name

Prohibit computing constant values of complex boolean expressions in when condition branches and conditions of loops

Make when statements with enum, sealed, and Boolean subjects exhaustive by default

Deprecate confusing grammar in when-with-subject

Type nullability enhancement improvements

Prevent implicit coercions between different numeric types

Deprecate the enable and the compatibility modes of the compiler option -Xjvm-default

Prohibit calls to functions named suspend with a trailing lambda

Prohibit smart cast on a base class property if the base class is from another module

Do not neglect meaningful constraints during type inference

Standard library

Gradually change the return type of collection min and max functions to non-nullable

Deprecate floating-point array functions: contains, indexOf, lastIndexOf

Migrate declarations from kotlin.dom and kotlin.browser packages to kotlinx.*

Deprecate some JS-only API

Tools

Remove KotlinGradleSubplugin class

Remove useIR compiler option

Deprecate kapt.use.worker.api Gradle property

Remove kotlin.experimental.coroutines Gradle DSL option and kotlin.coroutines Gradle property

Deprecate useExperimentalAnnotation compiler option

Deprecate kotlin.compiler.execution.strategy system property

Remove kotlinOptions.jdkHome compiler option

Remove noStdlib compiler option

Remove kotlin2js and kotlin-dce-plugin plugins

Changes in compile tasks

Last modified: 25 September 2024