Skip to content

Commit e8bff87

Browse files
authored
Fix compiler issue with Kotlin 1.9 and Backlinks (#1470)
1 parent 80313b9 commit e8bff87

File tree

8 files changed

+12
-6
lines changed

8 files changed

+12
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### Fixed
1010
* Rare corruption causing 'Invalid streaming format cookie'-exception. Typically following compact, convert or copying to a new file. (Issue [#1440](https://github.com/realm/realm-kotlin/issues/1440))
11+
* Compiler error when using Kotlin 1.9.0 and backlinks. (Issue [#1469](https://github.com/realm/realm-kotlin/issues/1469))
1112

1213
### Compatibility
1314
* File format: Generates Realms with file format v23.

buildSrc/src/main/kotlin/Config.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ object Versions {
127127
const val jvmTarget = "1.8"
128128
// When updating the Kotlin version, also remember to update /examples/min-android-sample/build.gradle.kts
129129
const val kotlin = "1.8.21" // https://github.com/JetBrains/kotlin and https://kotlinlang.org/docs/releases.html#release-details
130-
const val latestKotlin = "1.9.0-Beta" // https://kotlinlang.org/docs/eap.html#build-details
130+
const val latestKotlin = "1.9.0" // https://kotlinlang.org/docs/eap.html#build-details
131131
const val kotlinCompileTesting = "1.5.0" // https://github.com/tschuchortdev/kotlin-compile-testing
132132
const val ktlint = "0.45.2" // https://github.com/pinterest/ktlint
133133
const val ktor = "2.1.2" // https://github.com/ktorio/ktor

examples/kmm-sample/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ kotlin.mpp.enableGranularSourceSetsMetadata=true
2424
kotlin.native.enableDependencyPropagation=false
2525

2626
kotlin.mpp.stability.nowarn=true
27+
kotlin.mpp.androidSourceSetLayoutVersion1.nowarn=true

examples/kmm-sample/shared/src/commonMain/kotlin/io/realm/example/kmmsample/AllTypes.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package io.realm.example.kmmsample
1919

20+
import io.realm.kotlin.ext.backlinks
2021
import io.realm.kotlin.ext.realmListOf
2122
import io.realm.kotlin.types.ObjectId
2223
import io.realm.kotlin.types.RealmInstant
@@ -83,4 +84,7 @@ class AllTypes : RealmObject {
8384
var objectIdRealmList: RealmList<ObjectId> = realmListOf(ObjectId.create())
8485
var objectIdRealmListNullable: RealmList<ObjectId?> = realmListOf(null)
8586
var objectRealmList: RealmList<AllTypes> = realmListOf()
87+
88+
// Special types
89+
val parent by backlinks(AllTypes::objectField)
8690
}

packages/plugin-compiler/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ dependencies {
4444
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
4545
kotlinOptions {
4646
jvmTarget = "${Versions.jvmTarget}"
47-
freeCompilerArgs = listOf("-Xjvm-default=enable")
47+
freeCompilerArgs = listOf("-Xjvm-default=all-compatibility")
4848
}
4949
}
5050

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,11 +587,11 @@ fun getBacklinksTargetPropertyType(declaration: IrProperty): IrType? {
587587
fun getLinkingObjectPropertyName(backingField: IrField): String {
588588
(backingField.initializer!!.expression as IrCall).let { irCall ->
589589
val propertyReference = irCall.getValueArgument(0) as IrPropertyReference
590-
val targetProperty = propertyReference.symbol.owner
590+
val targetProperty: IrProperty = propertyReference.symbol.owner
591591
return if (targetProperty.hasAnnotation(PERSISTED_NAME_ANNOTATION)) {
592592
SchemaProperty.getPersistedName(targetProperty)
593593
} else {
594-
propertyReference.referencedName.identifier
594+
targetProperty.name.identifier
595595
}
596596
}
597597
}

packages/plugin-compiler/src/test/kotlin/io/realm/kotlin/compiler/GenerationExtensionTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ class GenerationExtensionTest {
402402
componentRegistrars = plugins
403403
inheritClassPath = true
404404
kotlincArguments = listOf(
405-
"-Xjvm-default=enable",
405+
"-Xjvm-default=all-compatibility",
406406
"-Xdump-directory=${inputs.outputDir()}",
407407
"-Xphases-to-dump-after=ValidateIrBeforeLowering"
408408
)

packages/test-base/src/jvmMain/kotlin/io/realm/kotlin/test/util/Compiler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ object Compiler {
3434
messageOutputStream = System.out
3535
componentRegistrars = plugins
3636
inheritClassPath = true
37-
kotlincArguments = listOf("-Xjvm-default=enable")
37+
kotlincArguments = listOf("-Xjvm-default=all-compatibility")
3838
}.compile()
3939
}

0 commit comments

Comments
 (0)