Kotlin Help

Compatibility guide for Kotlin 1.8

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.7 to Kotlin 1.8.

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

Prohibit the delegation of super calls to an abstract superclass member

Deprecate confusing grammar in when-with-subject

Prevent implicit coercions between different numeric types

Make private constructors of sealed classes really private

Prohibit using operator == on incompatible numeric types in builder inference context

Prohibit if without else and non-exhaustive when in right hand side of elvis operator

Prohibit upper bound violation in a generic type alias usage (one type parameter used in several type arguments of the aliased type)

Prohibit upper bound violation in a generic type alias usage (a type parameter used in a generic type argument of a type argument of the aliased type)

Prohibit using a type parameter declared for an extension property inside delegate

Forbid @Synchronized annotation on suspend functions

Prohibit using spread operator for passing arguments to non-vararg parameters

Prohibit null-safety violation in lambdas passed to functions overloaded by lambda return type

Keep nullability when approximating local types in public signatures

Do not propagate deprecation through overrides

Prohibit implicit inferring a type variable into an upper bound in the builder inference context

Prohibit using collection literals in annotation classes anywhere except their parameters declaration

Prohibit forward referencing of parameters with default values in default value expressions

Prohibit extension calls on inline functional parameters

Prohibit calls to infix functions named suspend with an anonymous function argument

Prohibit using captured type parameters in inner classes against their variance

Prohibit recursive call of a function without explicit return type in compound assignment operators

Prohibit unsound calls with expected @NotNull T and given Kotlin generic parameter with nullable bound

Prohibit access to members of a companion of an enum class from entry initializers of this enum

Deprecate and remove Enum.declaringClass synthetic property

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

Standard library

Warn about potential overload resolution change when Range/Progression starts implementing Collection

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

Deprecate some JS-only API

Tools

Raise deprecation level of classpath property of KotlinCompile task

Remove kapt.use.worker.api Gradle property

Remove kotlin.compiler.execution.strategy system property

Changes in compiler options

Deprecate kotlin.internal.single.build.metrics.file property

Last modified: 25 September 2024