본문으로 건너뛰기

Kotlin 1.9 호환성 가이드

언어의 현대성 유지 및 _편리한 업데이트_는 Kotlin 언어 디자인의 기본 원칙에 속합니다. 전자는 언어 발전을 저해하는 구문을 제거해야 한다고 말하며, 후자는 코드 마이그레이션을 최대한 원활하게 하기 위해 이러한 제거에 대해 사전에 충분히 알려야 한다고 말합니다.

대부분의 언어 변경 사항은 업데이트 변경 로그 또는 컴파일러 경고와 같은 다른 채널을 통해 이미 발표되었지만, 이 문서에서는 Kotlin 1.8에서 Kotlin 1.9로의 마이그레이션에 대한 완벽한 참조를 제공하면서 모든 변경 사항을 요약합니다.

기본 용어

이 문서에서는 여러 종류의 호환성을 소개합니다.

  • source(소스): source-incompatible(소스 비호환) 변경은 이전에는 (오류나 경고 없이) 정상적으로 컴파일되던 코드가 더 이상 컴파일되지 않도록 합니다.
  • binary(바이너리): 두 개의 바이너리 아티팩트를 서로 교환해도 로딩 또는 연결 오류가 발생하지 않으면 바이너리 호환이 된다고 합니다.
  • behavioral(동작): 변경 사항을 적용하기 전과 후에 동일한 프로그램이 다른 동작을 보이면 behavioral-incompatible(동작 비호환) 변경이라고 합니다.

이러한 정의는 순수 Kotlin에 대해서만 제공된다는 점을 기억하십시오. 다른 언어 관점에서 본 Kotlin 코드의 호환성 (예: Java에서)은 이 문서의 범위를 벗어납니다.

언어

언어 버전 1.3 제거

Issue: KT-61111

Component: Core language

Incompatible change type: source

Short summary: Kotlin 1.9는 언어 버전 1.9를 도입하고 언어 버전 1.3에 대한 지원을 제거합니다.

Deprecation cycle:

  • 1.6.0: report a warning
  • 1.9.0: raise the warning to an error

슈퍼 인터페이스 유형이 함수 리터럴인 경우 슈퍼 생성자 호출 금지

Issue: KT-46344

Component: Core language

Incompatible change type: source

Short summary: 인터페이스가 함수 리터럴 유형에서 상속되는 경우 Kotlin 1.9는 슈퍼 생성자가 존재하지 않으므로 슈퍼 생성자 호출을 금지합니다.

Deprecation cycle:

  • 1.7.0: report a warning (or an error in progressive mode)
  • 1.9.0: raise the warning to an error

어노테이션 파라미터 유형의 순환 금지

Issue: KT-47932

Component: Core language

Incompatible change type: source

Short summary: Kotlin 1.9는 어노테이션 유형이 직접 또는 간접적으로 파라미터 유형 중 하나로 사용되는 것을 금지합니다. 이렇게 하면 순환이 생성되는 것을 방지할 수 있습니다. 그러나 어노테이션 유형의 Array 또는 vararg인 파라미터 유형을 가질 수 있습니다.

Deprecation cycle:

  • 1.7.0: report a warning (or an error in progressive mode) on cycles in types of annotation parameters
  • 1.9.0: raise the warning to an error, -XXLanguage:-ProhibitCyclesInAnnotations can be used to temporarily revert to pre-1.9 behavior

파라미터가 없는 함수 유형에 @ExtensionFunctionType 어노테이션 사용 금지

Issue: KT-43527

Component: Core language

Incompatible change type: source

Short summary: Kotlin 1.9는 파라미터가 없는 함수 유형 또는 함수 유형이 아닌 유형에 @ExtensionFunctionType 어노테이션을 사용하는 것을 금지합니다.

Deprecation cycle:

  • 1.7.0: report a warning for annotations on types that aren't function types, report an error for annotations on types that are function types
  • 1.9.0: raise the warning for function types to an error

Java 필드 유형 불일치 시 할당 금지

Issue: KT-48994

Component: Kotlin/JVM

Incompatible change type: source

Short summary: Kotlin 1.9는 Java 필드에 할당된 값의 유형이 Java 필드의 예상 유형과 일치하지 않는 경우 컴파일러 오류를 보고합니다.

Deprecation cycle:

  • 1.6.0: report a warning (or an error in the progressive mode) when a projected Java field type doesn't match the assigned value type
  • 1.9.0: raise the warning to an error, -XXLanguage:-RefineTypeCheckingOnAssignmentsToJavaFields can be used to temporarily revert to pre-1.9 behavior

플랫폼 유형 nullability assertion 예외에서 소스 코드 발췌문 없음

Issue: KT-57570

Component: Kotlin/JVM

Incompatible change type: behavioral

Short summary: Kotlin 1.9에서 표현식 null 검사에 대한 예외 메시지에는 소스 코드 발췌문이 포함되지 않습니다. 대신 메서드 또는 필드 이름이 표시됩니다. 표현식이 메서드 또는 필드가 아니면 메시지에 추가 정보가 제공되지 않습니다.

Deprecation cycle:

  • < 1.9.0: exception messages generated by expression null checks contain source code excerpts
  • 1.9.0: exception messages generated by expression null checks contain method or field names only, -XXLanguage:-NoSourceCodeInNotNullAssertionExceptions can be used to temporarily revert to pre-1.9 behavior

추상 슈퍼클래스 멤버에 대한 슈퍼 호출 위임 금지

Issues: KT-45508, KT-49017, KT-38078

Component: Core language

Incompatible change type: source

Short summary: Kotlin은 명시적 또는 암시적 슈퍼 호출이 슈퍼 인터페이스에 기본 구현이 있더라도 슈퍼클래스의 추상 멤버에 위임되면 컴파일 오류를 보고합니다.

Deprecation cycle:

  • 1.5.20: introduce a warning when non-abstract classes that do not override all abstract members are used
  • 1.7.0: report a warning if a super call, in fact, accesses an abstract member from a superclass
  • 1.7.0: report an error in all affected cases if the -Xjvm-default=all or -Xjvm-default=all-compatibility compatibility modes are enabled; report an error in the progressive mode
  • 1.8.0: report an error in cases of declaring a concrete class with a non-overridden abstract method from the superclass, and super calls of Any methods are overridden as abstract in the superclass
  • 1.9.0: report an error in all affected cases, including explicit super calls to an abstract method from the super class

when-with-subject에서 혼란스러운 문법 지원 중단

Issue: KT-48385

Component: Core language

Incompatible change type: source

Short summary: Kotlin 1.6은 when 조건식에서 여러 가지 혼란스러운 문법 구조를 지원 중단했습니다.

Deprecation cycle:

  • 1.6.20: introduce a deprecation warning on the affected expressions
  • 1.8.0: raise this warning to an error, -XXLanguage:-ProhibitConfusingSyntaxInWhenBranches can be used to temporarily revert to the pre-1.8 behavior
  • >= 2.1: repurpose some deprecated constructs for new language features

서로 다른 숫자 유형 간의 암시적 강제 변환 방지

Issue: KT-48645

Component: Kotlin/JVM

Incompatible change type: behavioral

Short summary: Kotlin은 의미적으로 해당 유형으로의 다운캐스트만 필요한 경우 숫자 값을 원시 숫자 유형으로 자동 변환하는 것을 방지합니다.

Deprecation cycle:

  • < 1.5.30: the old behavior in all affected cases
  • 1.5.30: fix the downcast behavior in generated property delegate accessors, -Xuse-old-backend can be used to temporarily revert to the pre-1.5.30 fix behavior
  • >= 2.0: fix the downcast behavior in other affected cases

제네릭 유형 별칭 사용 시 상한 위반 금지 (별칭 유형의 유형 인수의 유형 인수에서 사용되는 유형 파라미터)

Issue: KT-54066

Component: Core language

Incompatible change type: source

Short summary: Kotlin은 typealias Alias<T> = Base<List<T>>와 같이 typealias 유형 파라미터가 별칭 유형의 유형 인수의 제네릭 유형 인수로 사용되는 경우, 별칭 유형의 해당 유형 파라미터의 상한 제한을 위반하는 유형 인수를 사용하여 유형 별칭을 사용하는 것을 금지합니다.

Deprecation cycle:

  • 1.8.0: report a warning when a generic typealias usage has type arguments violating upper bound constraints of the corresponding type parameters of the aliased type
  • 2.0.0: raise the warning to an error

공용 시그니처에서 로컬 유형을 근사화할 때 nullability 유지

Issue: KT-53982

Component: Core language

Incompatible change type: source, binary

Short summary: 로컬 또는 익명 유형이 명시적으로 지정된 반환 유형 없이 expression-body 함수에서 반환되면 Kotlin 컴파일러는 해당 유형의 알려진 슈퍼 유형을 사용하여 반환 유형을 추론(또는 근사화)합니다. 이 과정에서 컴파일러는 null 값을 실제로 반환할 수 있는 non-nullable 유형을 추론할 수 있습니다.

Deprecation cycle:

  • 1.8.0: approximate flexible types by flexible supertypes
  • 1.8.0: report a warning when a declaration is inferred to have a non-nullable type that should be nullable, prompting users to specify the type explicitly
  • 2.0.0: approximate nullable types by nullable supertypes, -XXLanguage:-KeepNullabilityWhenApproximatingLocalType can be used to temporarily revert to the pre-2.0 behavior

재정의를 통해 지원 중단 전파하지 않음

Issue: KT-47902

Component: Core language

Incompatible change type: source

Short summary: Kotlin 1.9는 더 이상 슈퍼클래스의 지원 중단된 멤버에서 서브클래스의 재정의 멤버로 지원 중단을 전파하지 않으므로 슈퍼클래스의 멤버를 지원 중단하면서 서브클래스에서는 지원 중단되지 않은 상태로 유지하는 명시적 메커니즘을 제공합니다.

Deprecation cycle:

  • 1.6.20: reporting a warning with the message of the future behavior change and a prompt to either suppress this warning or explicitly write a @Deprecated annotation on an override of a deprecated member
  • 1.9.0: stop propagating deprecation status to the overridden members. This change also takes effect immediately in the progressive mode

어노테이션 클래스의 파라미터 선언을 제외한 모든 곳에서 컬렉션 리터럴 사용 금지

Issue: KT-39041

Component: Core language

Incompatible change type: source

Short summary: Kotlin은 제한된 방식으로 컬렉션 리터럴을 사용할 수 있습니다. 어노테이션 클래스의 파라미터에 배열을 전달하거나 이러한 파라미터에 대한 기본값을 지정하는 데 사용할 수 있습니다. 그러나 그 외에도 Kotlin은 어노테이션 클래스 내부의 다른 모든 곳, 예를 들어 중첩된 객체에서 컬렉션 리터럴을 사용할 수 있었습니다. Kotlin 1.9는 어노테이션 클래스의 파라미터 기본값을 제외한 모든 곳에서 컬렉션 리터럴을 사용하는 것을 금지합니다.

Deprecation cycle:

  • 1.7.0: report a warning (or an error in the progressive mode) on array literals in nested objects in annotation classes
  • 1.9.0: raise the warning to an error

기본값 표현식에서 파라미터의 forward referencing 금지

Issue: KT-25694

Component: Core language

Incompatible change type: source

Short summary: Kotlin 1.9는 다른 파라미터의 기본값 표현식에서 파라미터의 forward referencing을 금지합니다. 이렇게 하면 파라미터가 기본값 표현식에서 액세스될 때쯤에는 함수에 전달되거나 자체 기본값 표현식으로 초기화된 값이 이미 있는지 확인합니다.

Deprecation cycle:

  • 1.7.0: report a warning (or an error in the progressive mode) when a parameter with default value is references in default value of another parameter that comes before it
  • 1.9.0: raise the warning to an error, -XXLanguage:-ProhibitIllegalValueParameterUsageInDefaultArguments can be used to temporarily revert to the pre-1.9 behavior

인라인 함수형 파라미터에 대한 확장 호출 금지

Issue: KT-52502

Component: Core language

Incompatible change type: source

Short summary: Kotlin은 인라인 함수형 파라미터를 다른 인라인 함수에 전달할 수 있도록 허용했지만 항상 해당 코드를 컴파일할 때 컴파일러 예외가 발생했습니다. Kotlin 1.9는 이를 금지하여 컴파일러 충돌 대신 오류를 보고합니다.

Deprecation cycle:

  • 1.7.20: report a warning (or an error in the progressive mode) for inline extension calls on inline functional parameters
  • 1.9.0: raise the warning to an error

익명 함수 인수를 사용하여 suspend라는 infix 함수에 대한 호출 금지

Issue: KT-49264

Component: Core language

Incompatible change type: source

Short summary: Kotlin 1.9는 더 이상 익명 함수 리터럴로 전달된 함수 유형의 단일 인수를 갖는 suspend라는 infix 함수를 호출할 수 없습니다.

Deprecation cycle:

  • 1.7.20: report a warning on suspend infix calls with an anonymous function literal
  • 1.9.0: raise the warning to an error, -XXLanguage:-ModifierNonBuiltinSuspendFunError can be used to temporarily revert to the pre-1.9 behavior
  • TODO: Change how the suspend fun token sequence is interpreted by the parser

내부 클래스에서 캡처된 유형 파라미터를 해당 variance에 대해 사용하는 것을 금지합니다.

Issue: KT-50947

Component: Core language

Incompatible change type: source

Short summary: Kotlin 1.9는 해당 유형 파라미터의 선언된 variance를 위반하는 위치에서 해당 클래스의 내부 클래스에서 in 또는 out variance를 갖는 외부 클래스의 유형 파라미터를 사용하는 것을 금지합니다.

Deprecation cycle:

  • 1.7.0: report a warning (or an error in the progressive mode) when an outer class' type parameter usage position violates the variance rules of that parameter
  • 1.9.0: raise the warning to an error, -XXLanguage:-ReportTypeVarianceConflictOnQualifierArguments can be used to temporarily revert to the pre-1.9 behavior

복합 할당 연산자에서 명시적 반환 유형이 없는 함수에 대한 재귀 호출 금지

Issue: KT-48546

Component: Core language

Incompatible change type: source

Short summary: Kotlin 1.9는 현재 해당 함수 본문 내부의 다른 표현식에서와 마찬가지로 함수 본문 내부의 복합 할당 연산자 인수에서 명시적으로 지정된 반환 유형이 없는 함수를 호출하는 것을 금지합니다.

Deprecation cycle:

  • 1.7.0: report a warning (or an error in the progressive mode) when a function without explicitly specified return type is called recursively in that function's body in a compound assignment operator argument
  • 1.9.0: raise the warning to an error

예상되는 @NotNull T와 제공된 nullable 바운드가 있는 Kotlin 제네릭 파라미터로의 잘못된 호출 금지

Issue: KT-36770

Component: Kotlin/JVM

Incompatible change type: source

Short summary: Kotlin 1.9는 잠재적으로 nullable 제네릭 유형의 값이 Java 메서드의 @NotNull 어노테이션된 파라미터에 전달되는 메서드 호출을 금지합니다.

Deprecation cycle:

  • 1.5.20: report a warning when an unconstrained generic type parameter is passed where a non-nullable type is expected
  • 1.9.0: report a type mismatch error instead of the warning above,
    -XXLanguage:-ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated can be used to temporarily revert to the pre-1.8 behavior

이 enum의 항목 이니셜라이저에서 enum 클래스의 companion 멤버에 대한 액세스 금지

Issue: KT-49110

Component: Core language

Incompatible change type: source

Short summary: Kotlin 1.9는 enum 항목 이니셜라이저에서 enum의 companion 객체에 대한 모든 종류의 액세스를 금지합니다.

Deprecation cycle:

  • 1.6.20: report a warning (or an error in the progressive mode) on such companion member access
  • 1.9.0: raise the warning to an error, -XXLanguage:-ProhibitAccessToEnumCompanionMembersInEnumConstructorCall can be used to temporarily revert to the pre-1.8 behavior

Enum.declaringClass 합성 프로퍼티 지원 중단 및 제거

Issue: KT-49653

Component: Kotlin/JVM

Incompatible change type: source

Short summary: Kotlin은 Kotlin Enum 유형에 대해 이 메서드를 사용할 수 없더라도 기본 Java 클래스 java.lang.Enum의 메서드 getDeclaringClass()에서 생성된 Enum 값에서 합성 프로퍼티 declaringClass를 사용할 수 있도록 했습니다. Kotlin 1.9는 이 프로퍼티의 사용을 금지하고 대신 확장 프로퍼티 declaringJavaClass로 마이그레이션할 것을 제안합니다.

Deprecation cycle:

  • 1.7.0: report a warning (or an error in the progressive mode) on declaringClass property usages, propose the migration to declaringJavaClass extension
  • 1.9.0: raise the warning to an error, -XXLanguage:-ProhibitEnumDeclaringClass can be used to temporarily revert to the pre-1.9 behavior
  • 2.0.0: remove declaringClass synthetic property

컴파일러 옵션 -Xjvm-default의 활성화 및 호환성 모드 지원 중단

Issues: KT-46329, KT-54746

Component: Kotlin/JVM

Incompatible change type: source

Short summary: Kotlin 1.9는 -Xjvm-default 컴파일러 옵션의 enablecompatibility 모드를 사용하는 것을 금지합니다.

Deprecation cycle:

  • 1.6.20: introduce a warning on the enable and compatibility modes of the -Xjvm-default compiler option
  • 1.9.0: raise this warning to an error

빌더 추론 컨텍스트에서 유형 변수를 상한으로 암시적으로 추론하는 것을 금지합니다.

Issue: KT-47986

Component: Core language

Incompatible change type: source

Short summary: Kotlin 2.0은 현재 다른 컨텍스트에서와 마찬가지로 빌더 추론 람다 함수의 범위에서 사용 사이트 유형 정보가 없는 경우 유형 변수를 해당 유형 파라미터의 상한으로 추론하는 것을 금지합니다.

Deprecation cycle:

  • 1.7.20: report a warning (or an error in the progressive mode) when a type parameter is inferred into declared upper bounds in the absence of use-site type information
  • 2.0.0: raise the warning to an error

표준 라이브러리

Range/Progression이 Collection 구현을 시작할 때 잠재적인 오버로드 해결 변경에 대한 경고

Issue: KT-49276

Component: Core language / kotlin-stdlib

Incompatible change type: source

Short summary: Kotlin 1.9에서 표준 progressions 및 해당 progressions에서 상속된 구체적인 범위에서 Collection 인터페이스를 구현할 계획입니다. 이렇게 하면 일부 메서드의 오버로드에 요소와 컬렉션을 허용하는 두 가지 오버로드가 있는 경우 오버로드 해결에서 다른 오버로드가 선택될 수 있습니다. Kotlin은 범위 또는 진행 인수와 함께 오버로드된 메서드를 호출할 때 경고 또는 오류를 보고하여 이 상황을 표시합니다.

Deprecation cycle:

  • 1.6.20: report a warning when an overloaded method is called with the standard progression or its range inheritor as an argument if implementing the Collection interface by this progression/range leads to another overload being selected in this call in future
  • 1.8.0: raise this warning to an error
  • 2.1.0: stop reporting the error, implement Collection interface in progressions thus changing the overload resolution result in the affected cases

kotlin.dom 및 kotlin.browser 패키지의 선언을 kotlinx.*로 마이그레이션

Issue: KT-39330

Component: kotlin-stdlib (JS)

Incompatible change type: source

Short summary: kotlin.domkotlin.browser 패키지의 선언이 stdlib에서 추출할 준비를 하기 위해 해당 kotlinx.* 패키지로 이동되었습니다.

Deprecation cycle:

  • 1.4.0: introduce the replacement API in kotlinx.dom and kotlinx.browser packages
  • 1.4.0: deprecate the API in kotlin.dom and kotlin.browser packages and propose the new API above as a replacement
  • 1.6.0: raise the deprecation level to an error
  • 1.8.20: remove the deprecated functions from stdlib for JS-IR target
  • >= 2.0: move the API in kotlinx.* packages to a separate library

일부 JS 전용 API 지원 중단

Issue: KT-48587

Component: kotlin-stdlib (JS)

Incompatible change type: source

Short summary: stdlib의 여러 JS 전용 함수가 제거를 위해 지원 중단되었습니다. 여기에는 String.concat(String), String.match(regex: String), String.matches(regex: String) 및 비교 함수를 사용하는 배열의 sort 함수(예: Array<out T>.sort(comparison: (a: T, b: T) -> Int))가 포함됩니다.

Deprecation cycle:

  • 1.6.0: deprecate the affected functions with a warning
  • 1.9.0: raise the deprecation level to an error
  • >=2.0: remove the deprecated functions from the public API

도구

Gradle 설정에서 enableEndorsedLibs 플래그 제거

Issue: KT-54098

Component: Gradle

Incompatible change type: source

Short summary: enableEndorsedLibs 플래그는 더 이상 Gradle 설정에서 지원되지 않습니다.

Deprecation cycle:

  • < 1.9.0: enableEndorsedLibs flag is supported in Gradle setup
  • 1.9.0: enableEndorsedLibs flag is not supported in Gradle setup

Gradle conventions 제거

Issue: KT-52976

Component: Gradle

Incompatible change type: source

Short summary: Gradle conventions는 Gradle 7.1에서 지원 중단되었으며 Gradle 8에서 제거되었습니다.

Deprecation cycle:

  • 1.7.20: Gradle conventions deprecated
  • 1.9.0: Gradle conventions removed

KotlinCompile 작업의 classpath 프로퍼티 제거

Issue: KT-53748

Component: Gradle

Incompatible change type: source

Short summary: KotlinCompile 작업의 classpath 프로퍼티가 제거되었습니다.

Deprecation cycle:

  • 1.7.0: the classpath property is deprecated
  • 1.8.0: raise the deprecation level to an error
  • 1.9.0: remove the deprecated functions from the public API

kotlin.internal.single.build.metrics.file 프로퍼티 지원 중단

Issue: KT-53357

Component: Gradle

Incompatible change type: source

Short summary: 빌드 보고서에 대한 단일 파일을 정의하는 데 사용되는 kotlin.internal.single.build.metrics.file 프로퍼티를 지원 중단합니다. kotlin.build.report.output=single_file과 함께 kotlin.build.report.single_file 프로퍼티를 대신 사용하십시오.

Deprecation cycle:

  • 1.8.0: raise the deprecation level to a warning
  • >= 1.9: delete the property