From 926696d98a0783393fb39f0dfa19927b7f43e89a Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Tue, 1 Aug 2023 11:53:02 +0200 Subject: [PATCH 1/2] Fix bug using Kotlin 1.9.0 and Backlinks --- CHANGELOG.md | 29 +++++++++++++++++++ buildSrc/src/main/kotlin/Config.kt | 2 +- packages/plugin-compiler/build.gradle.kts | 2 +- .../io/realm/kotlin/compiler/IrUtils.kt | 4 +-- .../compiler/GenerationExtensionTest.kt | 2 +- .../io/realm/kotlin/test/util/Compiler.kt | 2 +- 6 files changed, 35 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a1a3340f9..b862291788 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,32 @@ +## 1.10.3 (YYYY-MM-DD) + +### Breaking Changes +* None. + +### Enhancements +* None. + +### Fixed +* Compiler error when using Kotlin 1.9.0 and backlinks. (Issue [#1469](https://github.com/realm/realm-kotlin/issues/1469)) + +### Compatibility +* File format: Generates Realms with file format v23. +* Realm Studio 13.0.0 or above is required to open Realms created by this version. +* This release is compatible with the following Kotlin releases: + * Kotlin 1.8.0 and above. The K2 compiler is not supported yet. + * Ktor 2.1.2 and above. + * Coroutines 1.7.0 and above. + * AtomicFu 0.18.3 and above. + * The new memory model only. See https://github.com/realm/realm-kotlin#kotlin-memory-model-and-coroutine-compatibility +* Minimum Kbson 0.3.0. +* Minimum Gradle version: 6.8.3. +* Minimum Android Gradle Plugin version: 4.1.3. +* Minimum Android SDK: 16. + +### Internal +* None. + + ## 1.10.2 (2023-07-21) ### Breaking Changes diff --git a/buildSrc/src/main/kotlin/Config.kt b/buildSrc/src/main/kotlin/Config.kt index e65f21a6d7..e89c4c4764 100644 --- a/buildSrc/src/main/kotlin/Config.kt +++ b/buildSrc/src/main/kotlin/Config.kt @@ -127,7 +127,7 @@ object Versions { const val jvmTarget = "1.8" // When updating the Kotlin version, also remember to update /examples/min-android-sample/build.gradle.kts const val kotlin = "1.8.21" // https://github.com/JetBrains/kotlin and https://kotlinlang.org/docs/releases.html#release-details - const val latestKotlin = "1.9.0-Beta" // https://kotlinlang.org/docs/eap.html#build-details + const val latestKotlin = "1.9.0" // https://kotlinlang.org/docs/eap.html#build-details const val kotlinCompileTesting = "1.5.0" // https://github.com/tschuchortdev/kotlin-compile-testing const val ktlint = "0.45.2" // https://github.com/pinterest/ktlint const val ktor = "2.1.2" // https://github.com/ktorio/ktor diff --git a/packages/plugin-compiler/build.gradle.kts b/packages/plugin-compiler/build.gradle.kts index 5dfd688326..1dd9133e7e 100644 --- a/packages/plugin-compiler/build.gradle.kts +++ b/packages/plugin-compiler/build.gradle.kts @@ -44,7 +44,7 @@ dependencies { tasks.withType { kotlinOptions { jvmTarget = "${Versions.jvmTarget}" - freeCompilerArgs = listOf("-Xjvm-default=enable") + freeCompilerArgs = listOf("-Xjvm-default=all-compatibility") } } diff --git a/packages/plugin-compiler/src/main/kotlin/io/realm/kotlin/compiler/IrUtils.kt b/packages/plugin-compiler/src/main/kotlin/io/realm/kotlin/compiler/IrUtils.kt index 49d337ae5d..047ab1ec3f 100644 --- a/packages/plugin-compiler/src/main/kotlin/io/realm/kotlin/compiler/IrUtils.kt +++ b/packages/plugin-compiler/src/main/kotlin/io/realm/kotlin/compiler/IrUtils.kt @@ -587,11 +587,11 @@ fun getBacklinksTargetPropertyType(declaration: IrProperty): IrType? { fun getLinkingObjectPropertyName(backingField: IrField): String { (backingField.initializer!!.expression as IrCall).let { irCall -> val propertyReference = irCall.getValueArgument(0) as IrPropertyReference - val targetProperty = propertyReference.symbol.owner + val targetProperty: IrProperty = propertyReference.symbol.owner return if (targetProperty.hasAnnotation(PERSISTED_NAME_ANNOTATION)) { SchemaProperty.getPersistedName(targetProperty) } else { - propertyReference.referencedName.identifier + targetProperty.name.identifier } } } diff --git a/packages/plugin-compiler/src/test/kotlin/io/realm/kotlin/compiler/GenerationExtensionTest.kt b/packages/plugin-compiler/src/test/kotlin/io/realm/kotlin/compiler/GenerationExtensionTest.kt index e43d7ad3ee..b6f0f9bd15 100644 --- a/packages/plugin-compiler/src/test/kotlin/io/realm/kotlin/compiler/GenerationExtensionTest.kt +++ b/packages/plugin-compiler/src/test/kotlin/io/realm/kotlin/compiler/GenerationExtensionTest.kt @@ -402,7 +402,7 @@ class GenerationExtensionTest { componentRegistrars = plugins inheritClassPath = true kotlincArguments = listOf( - "-Xjvm-default=enable", + "-Xjvm-default=all-compatibility", "-Xdump-directory=${inputs.outputDir()}", "-Xphases-to-dump-after=ValidateIrBeforeLowering" ) diff --git a/packages/test-base/src/jvmMain/kotlin/io/realm/kotlin/test/util/Compiler.kt b/packages/test-base/src/jvmMain/kotlin/io/realm/kotlin/test/util/Compiler.kt index 84d7d9838c..2375417402 100644 --- a/packages/test-base/src/jvmMain/kotlin/io/realm/kotlin/test/util/Compiler.kt +++ b/packages/test-base/src/jvmMain/kotlin/io/realm/kotlin/test/util/Compiler.kt @@ -34,6 +34,6 @@ object Compiler { messageOutputStream = System.out componentRegistrars = plugins inheritClassPath = true - kotlincArguments = listOf("-Xjvm-default=enable") + kotlincArguments = listOf("-Xjvm-default=all-compatibility") }.compile() } From f144fc127651c685b00c8ee66f2197a9e883cea6 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Tue, 1 Aug 2023 12:09:01 +0200 Subject: [PATCH 2/2] Add backlinks to kmm-sample --- examples/kmm-sample/gradle.properties | 1 + .../commonMain/kotlin/io/realm/example/kmmsample/AllTypes.kt | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/examples/kmm-sample/gradle.properties b/examples/kmm-sample/gradle.properties index eff7ec4f56..abfa6de207 100644 --- a/examples/kmm-sample/gradle.properties +++ b/examples/kmm-sample/gradle.properties @@ -24,3 +24,4 @@ kotlin.mpp.enableGranularSourceSetsMetadata=true kotlin.native.enableDependencyPropagation=false kotlin.mpp.stability.nowarn=true +kotlin.mpp.androidSourceSetLayoutVersion1.nowarn=true diff --git a/examples/kmm-sample/shared/src/commonMain/kotlin/io/realm/example/kmmsample/AllTypes.kt b/examples/kmm-sample/shared/src/commonMain/kotlin/io/realm/example/kmmsample/AllTypes.kt index 982dc8b5e2..8231e877b9 100644 --- a/examples/kmm-sample/shared/src/commonMain/kotlin/io/realm/example/kmmsample/AllTypes.kt +++ b/examples/kmm-sample/shared/src/commonMain/kotlin/io/realm/example/kmmsample/AllTypes.kt @@ -17,6 +17,7 @@ package io.realm.example.kmmsample +import io.realm.kotlin.ext.backlinks import io.realm.kotlin.ext.realmListOf import io.realm.kotlin.types.ObjectId import io.realm.kotlin.types.RealmInstant @@ -83,4 +84,7 @@ class AllTypes : RealmObject { var objectIdRealmList: RealmList = realmListOf(ObjectId.create()) var objectIdRealmListNullable: RealmList = realmListOf(null) var objectRealmList: RealmList = realmListOf() + + // Special types + val parent by backlinks(AllTypes::objectField) }