Skip to content

Commit 46f5e80

Browse files
Fix compiler crash when using Kotlin 2.0.20 (#1830)
* Update Kotlin to 2.0.20 & dependencies --------- Co-authored-by: KitsuneAlex <[email protected]>
1 parent 326139a commit 46f5e80

File tree

11 files changed

+75
-28
lines changed

11 files changed

+75
-28
lines changed

CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 2.2.0 (2024-09-13)
1+
## 2.3.0-SNAPSHOT (YYYY-MM-DD)
22

33
### Breaking Changes
44
* None.
@@ -19,6 +19,7 @@
1919
* [Sync] Client reset cycle detection now checks if the previous recovery attempt was made by the same core version, and if not attempts recovery again (Core issue [realm/realm-core#7944](https://github.com/realm/realm-core/pull/7944)).
2020

2121
### Fixed
22+
* Via https://github.com/realm/realm-kotlin/pull/1826. Fix compiler crash caused by a change in Kotlin 2.0.20. (Issue [#1825](https://github.com/realm/realm-kotlin/issues/1825)). Thanks @KitsuneAlex.
2223
* Comparing a numeric property with an argument list containing a string would throw. (Core issue [realm/realm-core#7714](https://github.com/realm/realm-core/issues/7714), since v2.0.0).
2324
* After compacting, a file upgrade would be triggered. This could cause loss of data if schema mode is SoftResetFile (Core issue [realm/realm-core#7747](https://github.com/realm/realm-core/issues/7747), since v1.15.0).
2425
* Encrypted files on Windows had a maximum size of 2GB even on x64 due to internal usage of `off_t`, which is a 32-bit type on 64-bit Windows (Core issue [realm/realm-core#7698](https://github.com/realm/realm-core/pull/7698)).
@@ -46,7 +47,7 @@
4647
* File format: Generates Realms with file format v24 (reads and upgrades file format v10 or later).
4748
* Realm Studio 15.0.0 or above is required to open Realms created by this version.
4849
* This release is compatible with the following Kotlin releases:
49-
* Kotlin 2.0.0 and above. Support for experimental K2-compilation with `kotlin.experimental.tryK2=true`.
50+
* Kotlin 2.0.20 and above. Support for experimental K2-compilation with `kotlin.experimental.tryK2=true`.
5051
* Ktor 2.1.2 and above.
5152
* Coroutines 1.7.0 and above.
5253
* AtomicFu 0.18.3 and above.

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
[![Gradle Plugin Portal](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/io/realm/kotlin/io.realm.kotlin.gradle.plugin/maven-metadata.xml.svg?colorB=ff6b00&label=Gradle%20Plugin%20Portal)](https://plugins.gradle.org/plugin/io.realm.kotlin)
77
[![Maven Central](https://img.shields.io/maven-central/v/io.realm.kotlin/gradle-plugin?colorB=4dc427&label=Maven%20Central)](https://search.maven.org/artifact/io.realm.kotlin/gradle-plugin)
8-
[![Kotlin](https://img.shields.io/badge/kotlin-2.0.0-blue.svg?logo=kotlin)](http://kotlinlang.org)
8+
[![Kotlin](https://img.shields.io/badge/kotlin-2.0.20-blue.svg?logo=kotlin)](http://kotlinlang.org)
99
[![License](https://img.shields.io/badge/License-Apache-blue.svg)](https://github.com/realm/realm-kotlin/blob/master/LICENSE)
1010

1111

@@ -328,6 +328,7 @@ SDK supports. In the matrix below, you will find the minimum supported version f
328328

329329
| Realm Version | Requirements |
330330
|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
331+
| 2.3.0 | <ul><li>Kotlin 2.0.20+</li><li>AtomicFu 0.18.3+.</li><li>Ktor 2.1.2+.</li><li>Coroutines 1.7.0+.</li><li>Gradle 7.2 - 8.5</li><li>The new memory model only.</li></ul> |
331332
| 2.0.0 | <ul><li>Kotlin 2.0.0+</li><li>AtomicFu 0.18.3+.</li><li>Ktor 2.1.2+.</li><li>Coroutines 1.7.0+.</li><li>Gradle 7.2 - 8.5</li><li>The new memory model only.</li></ul> |
332333
| 1.16.0 | <ul><li>Kotlin 1.9.0+</li><li>AtomicFu 0.18.3+.</li><li>Ktor 2.1.2+.</li><li>Coroutines 1.7.0+.</li><li>Gradle 6.8.3 - 8.5</li><li>The new memory model only.</li></ul> |
333334
| 1.15.0 | <ul><li>Kotlin 1.9.0+</li><li>AtomicFu 0.18.3+.</li><li>Ktor 2.1.2+.</li><li>Coroutines 1.7.0+.</li><li>Gradle 6.8.3 - 8.5</li><li>The new memory model only.</li></ul> |

buildSrc/src/main/kotlin/Config.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ val HOST_OS: OperatingSystem = findHostOs()
6262

6363
object Realm {
6464
val ciBuild = (System.getenv("CI") != null)
65-
const val version = "2.2.0"
65+
const val version = "2.3.0-SNAPSHOT"
6666
const val group = "io.realm.kotlin"
6767
const val projectUrl = "https://realm.io"
6868
const val pluginPortalId = "io.realm.kotlin"
@@ -123,15 +123,15 @@ object Versions {
123123
const val junit = "4.13.2" // https://mvnrepository.com/artifact/junit/junit
124124
const val kbson = "0.4.0" // https://github.com/mongodb/kbson
125125
// When updating the Kotlin version, also remember to update /examples/min-android-sample/build.gradle.kts
126-
const val kotlin = "2.0.0" // https://github.com/JetBrains/kotlin and https://kotlinlang.org/docs/releases.html#release-details
126+
const val kotlin = "2.0.20" // https://github.com/JetBrains/kotlin and https://kotlinlang.org/docs/releases.html#release-details
127127
const val kotlinJvmTarget = "1.8" // Which JVM bytecode version is kotlin compiled to.
128-
const val latestKotlin = "2.0.0" // https://kotlinlang.org/docs/eap.html#build-details
129-
const val kotlinCompileTesting = "0.5.0-alpha07" // https://github.com/zacsweers/kotlin-compile-testing
128+
const val latestKotlin = "2.0.20" // https://kotlinlang.org/docs/eap.html#build-details
129+
const val kotlinCompileTesting = "0.5.1" // https://github.com/zacsweers/kotlin-compile-testing
130130
const val ktlint = "0.45.2" // https://github.com/pinterest/ktlint
131131
const val ktor = "2.3.12" // https://github.com/ktorio/ktor
132132
const val multidex = "2.0.1" // https://developer.android.com/jetpack/androidx/releases/multidex
133-
const val nexusPublishPlugin = "1.1.0" // https://github.com/gradle-nexus/publish-plugin
134-
const val okio = "3.2.0" // https://square.github.io/okio/#releases
133+
const val nexusPublishPlugin = "1.3.0" // https://github.com/gradle-nexus/publish-plugin
134+
const val okio = "3.9.0" // https://square.github.io/okio/#releases
135135
const val relinker = "1.4.5" // https://github.com/KeepSafe/ReLinker
136136
const val serialization = "1.7.1" // https://kotlinlang.org/docs/releases.html#release-details
137137
const val shadowJar = "6.1.0" // https://mvnrepository.com/artifact/com.github.johnrengelman.shadow/com.github.johnrengelman.shadow.gradle.plugin?repo=gradle-plugins

examples/min-android-sample/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ buildscript {
1616
}
1717
dependencies {
1818
classpath("com.android.tools.build:gradle:7.1.3")
19-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0")
19+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20")
2020
classpath("io.realm.kotlin:gradle-plugin:${rootProject.extra["realmVersion"]}")
2121
}
2222
}

integration-tests/gradle/gradle72-test/build.gradle.kts

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ buildscript {
2626
it.substringAfter("\"").substringBefore("\"")
2727
}
2828

29+
extra["kotlinVersion"] = file("${rootProject.rootDir.absolutePath}/../../../buildSrc/src/main/kotlin/Config.kt")
30+
.readLines()
31+
.first { it.contains("const val kotlin") }
32+
.let {
33+
it.substringAfter("\"").substringBefore("\"")
34+
}
35+
2936
repositories {
3037
maven(url = "file://${rootProject.rootDir.absolutePath}/../../../packages/build/m2-buildrepo")
3138
gradlePluginPortal()
@@ -34,7 +41,7 @@ buildscript {
3441
}
3542
dependencies {
3643
classpath("com.android.tools.build:gradle:7.1.3")
37-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0")
44+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra["kotlinVersion"]}")
3845
classpath("io.realm.kotlin:gradle-plugin:${rootProject.extra["realmVersion"]}")
3946
}
4047
}

integration-tests/gradle/gradle75-test/build.gradle.kts

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ buildscript {
2626
it.substringAfter("\"").substringBefore("\"")
2727
}
2828

29+
extra["kotlinVersion"] = file("${rootProject.rootDir.absolutePath}/../../../buildSrc/src/main/kotlin/Config.kt")
30+
.readLines()
31+
.first { it.contains("const val kotlin") }
32+
.let {
33+
it.substringAfter("\"").substringBefore("\"")
34+
}
35+
2936
repositories {
3037
maven(url = "file://${rootProject.rootDir.absolutePath}/../../../packages/build/m2-buildrepo")
3138
gradlePluginPortal()
@@ -34,7 +41,7 @@ buildscript {
3441
}
3542
dependencies {
3643
classpath("com.android.tools.build:gradle:7.4.0")
37-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0")
44+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra["kotlinVersion"]}")
3845
classpath("io.realm.kotlin:gradle-plugin:${rootProject.extra["realmVersion"]}")
3946
}
4047
}

integration-tests/gradle/gradle8-test/build.gradle.kts

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ buildscript {
2626
it.substringAfter("\"").substringBefore("\"")
2727
}
2828

29+
extra["kotlinVersion"] = file("${rootProject.rootDir.absolutePath}/../../../buildSrc/src/main/kotlin/Config.kt")
30+
.readLines()
31+
.first { it.contains("const val kotlin") }
32+
.let {
33+
it.substringAfter("\"").substringBefore("\"")
34+
}
35+
2936
repositories {
3037
maven(url = "file://${rootProject.rootDir.absolutePath}/../../../packages/build/m2-buildrepo")
3138
gradlePluginPortal()
@@ -34,7 +41,7 @@ buildscript {
3441
}
3542
dependencies {
3643
classpath("com.android.tools.build:gradle:8.1.0")
37-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0")
44+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra["kotlinVersion"]}")
3845
classpath("io.realm.kotlin:gradle-plugin:${rootProject.extra["realmVersion"]}")
3946
}
4047
}

integration-tests/gradle/gradle85-test/build.gradle.kts

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ buildscript {
2626
it.substringAfter("\"").substringBefore("\"")
2727
}
2828

29+
extra["kotlinVersion"] = file("${rootProject.rootDir.absolutePath}/../../../buildSrc/src/main/kotlin/Config.kt")
30+
.readLines()
31+
.first { it.contains("const val kotlin") }
32+
.let {
33+
it.substringAfter("\"").substringBefore("\"")
34+
}
35+
2936
repositories {
3037
maven(url = "file://${rootProject.rootDir.absolutePath}/../../../packages/build/m2-buildrepo")
3138
gradlePluginPortal()
@@ -34,7 +41,7 @@ buildscript {
3441
}
3542
dependencies {
3643
classpath("com.android.tools.build:gradle:8.1.0")
37-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0")
44+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra["kotlinVersion"]}")
3845
classpath("io.realm.kotlin:gradle-plugin:${rootProject.extra["realmVersion"]}")
3946
}
4047
}

packages/plugin-compiler/src/main/kotlin/io/realm/kotlin/compiler/IrUtils.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ import org.jetbrains.kotlin.ir.types.IrType
9797
import org.jetbrains.kotlin.ir.types.IrTypeArgument
9898
import org.jetbrains.kotlin.ir.types.getClass
9999
import org.jetbrains.kotlin.ir.types.impl.IrAbstractSimpleType
100-
import org.jetbrains.kotlin.ir.types.impl.IrTypeBase
101100
import org.jetbrains.kotlin.ir.types.makeNullable
102101
import org.jetbrains.kotlin.ir.types.typeWith
103102
import org.jetbrains.kotlin.ir.util.classId
@@ -633,7 +632,7 @@ fun getCollectionElementType(backingFieldType: IrType): IrType? {
633632
@Suppress("UNCHECKED_CAST")
634633
val values: List<IrTypeArgument> = args.get(backingFieldType) as List<IrTypeArgument>
635634
if (values.isNotEmpty()) {
636-
return (values[0] as IrTypeBase).type
635+
return (values[0] as IrType).type
637636
}
638637
}
639638
return null

packages/plugin-compiler/src/main/kotlin/io/realm/kotlin/compiler/RealmModelLoweringExtension.kt

+15-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.backend.common.CompilationException
2626
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
2727
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
2828
import org.jetbrains.kotlin.backend.common.runOnFilePostfix
29-
import org.jetbrains.kotlin.backend.common.wrapWithCompilationException
3029
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
3130
import org.jetbrains.kotlin.ir.declarations.IrClass
3231
import org.jetbrains.kotlin.ir.declarations.IrFile
@@ -76,15 +75,25 @@ private class RealmModelLowering(private val pluginContext: IrPluginContext) : C
7675
// Unfortunately we cannot access the IR element of e uniformly across 1.9 and 2.0 so
7776
// leaving it as null. Hopefully the embedded cause will give the appropriate pointers
7877
// to fix this.
79-
throw e.wrapWithCompilationException("Internal error in realm lowering", it, null)
78+
throw CompilationException(
79+
"Internal error in realm lowering : ${this::class.qualifiedName}: ${e.message}",
80+
it,
81+
null,
82+
cause = e
83+
).apply {
84+
stackTrace = e.stackTrace
85+
}
8086
} catch (e: KotlinExceptionWithAttachments) {
8187
throw e
8288
} catch (e: Throwable) {
83-
throw e.wrapWithCompilationException(
84-
"Internal error in file lowering",
89+
throw CompilationException(
90+
"Internal error in file lowering : ${this::class.qualifiedName}: ${e.message}",
8591
it,
86-
null
87-
)
92+
null,
93+
cause = e
94+
).apply {
95+
stackTrace = e.stackTrace
96+
}
8897
}
8998
}
9099

packages/plugin-compiler/src/main/kotlin/io/realm/kotlin/compiler/SyncLoweringExtension.kt

+15-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.backend.common.DeclarationContainerLoweringPass
2525
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
2626
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
2727
import org.jetbrains.kotlin.backend.common.runOnFilePostfix
28-
import org.jetbrains.kotlin.backend.common.wrapWithCompilationException
2928
import org.jetbrains.kotlin.ir.declarations.IrClass
3029
import org.jetbrains.kotlin.ir.declarations.IrDeclarationContainer
3130
import org.jetbrains.kotlin.ir.declarations.IrFile
@@ -180,15 +179,25 @@ private class SyncLowering(private val pluginContext: IrPluginContext, private v
180179
// Unfortunately we cannot access the IR element of e uniformly across 1.9 and 2.0 so
181180
// leaving it as null. Hopefully the embedded cause will give the appropriate pointers
182181
// to fix this.
183-
throw e.wrapWithCompilationException("Internal error in realm lowering", it, null)
182+
throw CompilationException(
183+
"Internal error in realm lowering : ${this::class.qualifiedName}: ${e.message}",
184+
it,
185+
null,
186+
cause = e
187+
).apply {
188+
stackTrace = e.stackTrace
189+
}
184190
} catch (e: KotlinExceptionWithAttachments) {
185191
throw e
186192
} catch (e: Throwable) {
187-
throw e.wrapWithCompilationException(
188-
"Internal error in file lowering",
193+
throw CompilationException(
194+
"Internal error in file lowering : ${this::class.qualifiedName}: ${e.message}",
189195
it,
190-
null
191-
)
196+
null,
197+
cause = e
198+
).apply {
199+
stackTrace = e.stackTrace
200+
}
192201
}
193202
}
194203

0 commit comments

Comments
 (0)