Skip to content

Commit c53aa14

Browse files
committed
Disable derived numerical types
1 parent 43dd5dc commit c53aa14

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

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

+13-8
Original file line numberDiff line numberDiff line change
@@ -301,26 +301,31 @@ class AccessorModifierIrGeneration(private val pluginContext: IrPluginContext) {
301301
val typeAdapterMethodReferences = if(declaration.hasAnnotation(TYPE_ADAPTER_ANNOTATION)) {
302302
logDebug("Object property named ${declaration.name} is an adapted type.")
303303

304-
// TODO throw on unsupported types
305-
306304
val adapterClassReference =
307305
declaration.getAnnotation(TYPE_ADAPTER_ANNOTATION.asSingleFqName())
308306
.getValueArgument(0)!! as IrClassReference
309307
val adapterClass: IrClass = adapterClassReference.classType.getClass()!!
310308

311-
// TODO find correct super type adapter type, might be multiple ones
309+
// TODO find correct super type adapter type, might be multiple ones because inheritance
312310
val (realmType: IrTypeArgument, userType) =
313311
(adapterClassReference.symbol.superTypes().first() as IrSimpleType)
314312
.arguments
315313
.let { arguments ->
316314
arguments[0] to arguments[1]
317315
}
318316

319-
// TODO throw proper error on null
320-
// replace the property type with the one from the type adapter
321-
realmType.typeOrNull!!.let {
322-
propertyType = it.makeNotNull()
323-
nullable = it.isNullable()
317+
// Replace the property type with the one from the type adapter
318+
realmType.typeOrNull.let {
319+
if(it != null) {
320+
propertyType = it.makeNotNull()
321+
if(propertyType.isChar() || propertyType.isByte() || propertyType.isShort() || propertyType.isInt() || propertyType.isMutableRealmInteger()) {
322+
// TODO improve messaging
323+
logError("Unsupported Realm storage type. Use `Long` instead", declaration.locationOf())
324+
}
325+
nullable = it.isNullable()
326+
} else {
327+
logError("Could not retrieve the storage type.")
328+
}
324329
}
325330

326331
when (adapterClass.kind) {

packages/test-base/src/jvmTest/kotlin/io/realm/kotlin/test/compiler/TypeAdaptersTests.kt

+7-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,13 @@ class TypeAdaptersTests {
143143

144144
allFieldTypes
145145
.filterNot { type ->
146-
// // TODO tidy list unsupported types in TypeDescriptor
147-
type.elementType.classifier == RealmObject::class
146+
// TODO tidy list unsupported types in TypeDescriptor
147+
type.elementType.classifier == RealmObject::class ||
148+
type.elementType.classifier == Byte::class ||
149+
type.elementType.classifier == Char::class ||
150+
type.elementType.classifier == Short::class ||
151+
type.elementType.classifier == Int::class ||
152+
type.elementType.classifier == MutableRealmInt::class
148153
}
149154
.forEach { type ->
150155
val elementType = type.elementType

0 commit comments

Comments
 (0)