Kotlin Help

Compatibility guide for Kotlin 2.0

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 updated changelogs or compiler warnings, this document provides a complete reference for migration from Kotlin 1.9 to Kotlin 2.0.

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

Deprecate use of a synthetic setter on a projected receiver

Other language changes

Issue ID

Title

KT-57871

K1/K2 inconsistency on if-conditional without else-branch in parenthesis

KT-61718

Forbid unsound code with self upper bounds and captured types

KT-54862

Anonymous type can be exposed from private inline function from type argument

KT-37592

Property invoke of a functional type with receiver is preferred over extension function invoke

KT-51194

False negative CONFLICTING_INHERITED_MEMBERS when dependency class contained in two different versions of the same dependency

KT-57609

K2: Stop relying on the presence of @UnsafeVariance using for contravariant parameters

KT-54316

Out-of-call reference to companion object's member has invalid signature

KT-55111

OptIn: forbid constructor calls with default arguments under marker

KT-33917

Prohibit to expose anonymous types from private inline functions

KT-56408

Inconsistent rules of CFA in class initialization block between K1 and K2

KT-57750

Report ambiguity error when resolving types and having the same-named classes star imported

KT-49404

Fix type unsoundness for contravariant captured type based on Java class

KT-22379

Condition of while-loop with break can produce unsound smartcast

KT-53752

Missed subtyping check for an intersection type

KT-52628

Deprecate SAM constructor usages which require OptIn without annotation

KT-54066

Deprecate upper bound violation in typealias constructors

KT-57011

Make real type of a destructuring variable consistent with explicit type when specified

KT-52802

Report ambiguity resolving between property/field and enum entry

KT-58260

Make invoke convention work consistently with expected desugaring

KT-55179

False negative PRIVATE_CLASS_MEMBER_FROM_INLINE on calling private class companion object member from internal inline function

KT-54663

Projected types don't take into account in-place not null types

KT-57178

Change inferred type of prefix increment to return type of getter instead of return type of inc() operator

KT-61749

Forbid unsound bound violation in generic inner class of generic outer class

KT-64342

SAM conversion of parameter types of callable references leads to CCE

KT-64299

Companion scope is ignored for resolution of annotations on companion object

KT-47310

Change qualifier resolution behavior when companion property is preferred against enum entry

KT-41034

K2: Change evaluation semantics for combination of safe calls and convention operators

KT-56545

Fix incorrect functions mangling in JVM backend in case of accidental clashing overload in a Java subclass

KT-58589

Deprecate missed MUST_BE_INITIALIZED when no primary constructor is presented or when class is local

KT-61182

Unit conversion is accidentally allowed to be used for expressions on variables + invoke resolution

KT-62998

Forbid assignment of a nullable to a not-null Java field as a selector of unsafe assignment

KT-57600

Forbid overriding of Java method with raw-typed parameter with generic typed parameter

KT-47313

Change (V)::foo reference resolution when V has a companion

KT-54997

Forbid implicit non-public-API accesses from public-API inline function

KT-57422

K2: Prohibit use-site 'get' targeted annotations on property getters

KT-34372

Report missed error for virtual inline method in enum classes

KT-47986

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

KT-53982

Keep nullability when approximating local types in public signatures

KT-45375

Generate all Kotlin lambdas via invokedynamic + LambdaMetafactory by default

KT-65776

[LC] K2 breaks `false && ...` and `false || ...`

Tools

Visibility changes in Gradle

Deprecate kotlinOptions DSL

Deprecate compilerOptions in KotlinCompilation DSL

Deprecate old ways of CInteropProcess handling

Remove kotlin.useK2 Gradle property

Remove deprecated platform plugin IDs

Last modified: 23 May 2024