@@ -77,6 +77,7 @@ import org.jetbrains.kotlin.ir.builders.irString
7777import org.jetbrains.kotlin.ir.builders.irTemporary
7878import org.jetbrains.kotlin.ir.declarations.IrClass
7979import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
80+ import org.jetbrains.kotlin.ir.declarations.IrParameterKind
8081import org.jetbrains.kotlin.ir.declarations.IrProperty
8182import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
8283import org.jetbrains.kotlin.ir.declarations.IrValueParameter
@@ -97,10 +98,10 @@ import org.jetbrains.kotlin.ir.types.isDouble
9798import org.jetbrains.kotlin.ir.types.isFloat
9899import org.jetbrains.kotlin.ir.types.isInt
99100import org.jetbrains.kotlin.ir.types.isLong
100- import org.jetbrains.kotlin.ir.types.isNullable
101+ // import org.jetbrains.kotlin.ir.types.isNullable
101102import org.jetbrains.kotlin.ir.types.isShort
102103import org.jetbrains.kotlin.ir.types.isString
103- import org.jetbrains.kotlin.ir.types.isSubtypeOfClass
104+ // import org.jetbrains.kotlin.ir.types.isSubtypeOfClass
104105import org.jetbrains.kotlin.ir.types.makeNotNull
105106import org.jetbrains.kotlin.ir.util.classId
106107import org.jetbrains.kotlin.ir.util.defaultType
@@ -117,8 +118,8 @@ import org.jetbrains.kotlin.types.StarProjectionImpl
117118import org.jetbrains.kotlin.types.isNullable
118119import org.jetbrains.kotlin.types.typeUtil.supertypes
119120import kotlin.collections.set
120- // import org.jetbrains.kotlin.ir.util.isNullable
121- // import org.jetbrains.kotlin.ir.util.isSubtypeOfClass
121+ import org.jetbrains.kotlin.ir.util.isNullable
122+ import org.jetbrains.kotlin.ir.util.isSubtypeOfClass
122123
123124/* *
124125 * Modifies the IR tree to transform getter/setter to call the C-Interop layer to retrieve read the managed values from the Realm
@@ -813,7 +814,7 @@ class AccessorModifierIrGeneration(private val pluginContext: IrPluginContext) {
813814 irCall(
814815 objectReferenceProperty.getter!! ,
815816 ).also {
816- it.dispatchReceiver = irGet(receiver)
817+ it.arguments[ 0 ] = irGet(receiver)
817818 },
818819 nameHint = " objectReference" ,
819820 irType = objectReferenceType,
@@ -822,13 +823,13 @@ class AccessorModifierIrGeneration(private val pluginContext: IrPluginContext) {
822823 callee = getFunction,
823824 origin = null
824825 ).also {
825- it.dispatchReceiver = irGetObject(realmObjectHelper.symbol)
826+ it.arguments[ 0 ] = irGetObject(realmObjectHelper.symbol)
826827 }.apply {
827828 if (typeArguments.isNotEmpty()) {
828829 typeArguments[0 ] = type
829830 }
830- arguments[0 ] = irGet(objectReferenceType, tmp.symbol)
831- arguments[1 ] = irString(property.persistedName)
831+ arguments[1 ] = irGet(objectReferenceType, tmp.symbol)
832+ arguments[2 ] = irString(property.persistedName)
832833 }
833834 val storageValue = fromRealmValue?.let {
834835 irCall(callee = it).apply {
@@ -887,16 +888,17 @@ class AccessorModifierIrGeneration(private val pluginContext: IrPluginContext) {
887888 irCall(
888889 objectReferenceProperty.getter!! ,
889890 ).also {
890- it.dispatchReceiver = irGet(receiver)
891+ it.arguments[ 0 ] = irGet(receiver)
891892 },
892893 nameHint = " objectReference" ,
893894 irType = objectReferenceType,
894895 )
896+ val params = parameters.filter { it.kind == IrParameterKind .Regular || it.kind == IrParameterKind .Context }
895897 val storageValue: IrDeclarationReference = fromPublic?.let {
896898 irCall(callee = it).apply {
897- arguments[0 ] = irGet(parameters .first())
899+ arguments[0 ] = irGet(params .first())
898900 }
899- } ? : irGet(parameters .first())
901+ } ? : irGet(params .first())
900902 val realmValue: IrDeclarationReference = toRealmValue?.let {
901903 irCall(callee = it).apply {
902904 if (typeArguments.isNotEmpty()) {
@@ -908,25 +910,24 @@ class AccessorModifierIrGeneration(private val pluginContext: IrPluginContext) {
908910 val cinteropCall = irCall(
909911 callee = setFunction,
910912 ).also {
911- it.dispatchReceiver = irGetObject(realmObjectHelper.symbol)
913+ it.arguments[ 0 ] = irGetObject(realmObjectHelper.symbol)
912914 }.apply {
913915 if (typeArguments.isNotEmpty()) {
914916 typeArguments[0 ] = type
915917 }
916- arguments[0 ] = irGet(objectReferenceType, tmp.symbol)
917- arguments[1 ] = irString(property.persistedName)
918- arguments[2 ] = realmValue
918+ arguments[1 ] = irGet(objectReferenceType, tmp.symbol)
919+ arguments[2 ] = irString(property.persistedName)
920+ arguments[3 ] = realmValue
919921 }
920922
921923 + irIfNull(
922924 type = pluginContext.irBuiltIns.unitType,
923925 subject = irGet(objectReferenceType, tmp.symbol),
924926 // Unmanaged object, set the backing field
925- thenPart =
926- irSetField(
927+ thenPart = irSetField(
927928 irGet(receiver),
928929 backingField.symbol.owner,
929- irGet(parameters .first()),
930+ irGet(params .first()),
930931 ),
931932 // Managed object, return realm value
932933 elsePart = cinteropCall
@@ -1073,28 +1074,24 @@ class AccessorModifierIrGeneration(private val pluginContext: IrPluginContext) {
10731074
10741075 // Otherwise just return the matching core type present in the declaration
10751076 val genericPropertyType: PropertyType ? = getPropertyTypeFromKotlinType(collectionGenericType)
1076- return when (genericPropertyType) {
1077- null -> {
1078- logError(
1079- " Unsupported type for ${collectionType.description} : '${collectionGenericType.getKotlinTypeFqNameCompat(true )
1080- } '" ,
1081- declaration.locationOf()
1082- )
1083- null
1084- }
1085- PropertyType .RLM_PROPERTY_TYPE_MIXED if ! collectionGenericType.isNullable() -> {
1086- logError(
1087- " Unsupported type for ${collectionType.description} : Only '${collectionType.description} <RealmAny?>' is supported." ,
1088- declaration.locationOf()
1089- )
1090- return null
1091- }
1092- else -> {
1093- CoreType (
1094- propertyType = genericPropertyType,
1095- nullable = collectionGenericType.isNullable()
1096- )
1097- }
1077+ return if (genericPropertyType == null ) {
1078+ logError(
1079+ " Unsupported type for ${collectionType.description} : '${collectionGenericType.getKotlinTypeFqNameCompat(true )
1080+ } '" ,
1081+ declaration.locationOf()
1082+ )
1083+ null
1084+ } else if (genericPropertyType == PropertyType .RLM_PROPERTY_TYPE_MIXED && ! collectionGenericType.isNullable()) {
1085+ logError(
1086+ " Unsupported type for ${collectionType.description} : Only '${collectionType.description} <RealmAny?>' is supported." ,
1087+ declaration.locationOf()
1088+ )
1089+ return null
1090+ } else {
1091+ CoreType (
1092+ propertyType = genericPropertyType,
1093+ nullable = collectionGenericType.isNullable()
1094+ )
10981095 }
10991096 }
11001097
0 commit comments