Skip to content

Commit

Permalink
Disable derived numerical types
Browse files Browse the repository at this point in the history
  • Loading branch information
clementetb committed Dec 5, 2023
1 parent 43dd5dc commit c53aa14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,26 +301,31 @@ class AccessorModifierIrGeneration(private val pluginContext: IrPluginContext) {
val typeAdapterMethodReferences = if(declaration.hasAnnotation(TYPE_ADAPTER_ANNOTATION)) {
logDebug("Object property named ${declaration.name} is an adapted type.")

// TODO throw on unsupported types

val adapterClassReference =
declaration.getAnnotation(TYPE_ADAPTER_ANNOTATION.asSingleFqName())
.getValueArgument(0)!! as IrClassReference
val adapterClass: IrClass = adapterClassReference.classType.getClass()!!

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

// TODO throw proper error on null
// replace the property type with the one from the type adapter
realmType.typeOrNull!!.let {
propertyType = it.makeNotNull()
nullable = it.isNullable()
// Replace the property type with the one from the type adapter
realmType.typeOrNull.let {
if(it != null) {
propertyType = it.makeNotNull()
if(propertyType.isChar() || propertyType.isByte() || propertyType.isShort() || propertyType.isInt() || propertyType.isMutableRealmInteger()) {
// TODO improve messaging
logError("Unsupported Realm storage type. Use `Long` instead", declaration.locationOf())
}
nullable = it.isNullable()
} else {
logError("Could not retrieve the storage type.")
}
}

when (adapterClass.kind) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,13 @@ class TypeAdaptersTests {

allFieldTypes
.filterNot { type ->
// // TODO tidy list unsupported types in TypeDescriptor
type.elementType.classifier == RealmObject::class
// TODO tidy list unsupported types in TypeDescriptor
type.elementType.classifier == RealmObject::class ||
type.elementType.classifier == Byte::class ||
type.elementType.classifier == Char::class ||
type.elementType.classifier == Short::class ||
type.elementType.classifier == Int::class ||
type.elementType.classifier == MutableRealmInt::class
}
.forEach { type ->
val elementType = type.elementType
Expand Down

0 comments on commit c53aa14

Please sign in to comment.