diff --git a/compiler-plugin/src/main/kotlin/tech/mappie/util/Ir.kt b/compiler-plugin/src/main/kotlin/tech/mappie/util/Ir.kt index b0e60970..91b15e7c 100644 --- a/compiler-plugin/src/main/kotlin/tech/mappie/util/Ir.kt +++ b/compiler-plugin/src/main/kotlin/tech/mappie/util/Ir.kt @@ -25,7 +25,16 @@ internal fun IrClass.allSuperTypes(): List = this.superTypes + this.superTypes.flatMap { it.erasedUpperBound.allSuperTypes() } fun IrType.isAssignableFrom(other: IrType): Boolean = - isSubtypeOf(other, IrTypeSystemContextImpl(context.irBuiltIns)) && (isNullable() || !other.isNullable()) + other.isSubtypeOf(this, IrTypeSystemContextImpl(context.irBuiltIns)) || isIntegerAssignableFrom(other) + +fun IrType.isIntegerAssignableFrom(other: IrType): Boolean = + when (other) { + context.irBuiltIns.byteType -> this in listOf(context.irBuiltIns.byteType) + context.irBuiltIns.shortType -> this in listOf(context.irBuiltIns.byteType, context.irBuiltIns.shortType) + context.irBuiltIns.intType -> this in listOf(context.irBuiltIns.byteType, context.irBuiltIns.shortType, context.irBuiltIns.intType) + context.irBuiltIns.longType -> this in listOf(context.irBuiltIns.byteType, context.irBuiltIns.shortType, context.irBuiltIns.intType, context.irBuiltIns.longType) + else -> false + } fun getterName(name: Name) = getterName(name.asString()) diff --git a/mappie-api/build.gradle.kts b/mappie-api/build.gradle.kts index 2f1e283a..c564783b 100644 --- a/mappie-api/build.gradle.kts +++ b/mappie-api/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.dokka.gradle.DokkaTask - plugins { alias(libs.plugins.kotlin.multiplatform) alias(libs.plugins.dokka) diff --git a/testing/src/main/kotlin/testing/IdentityMapper.kt b/testing/src/main/kotlin/testing/IntIdentityMapper.kt similarity index 67% rename from testing/src/main/kotlin/testing/IdentityMapper.kt rename to testing/src/main/kotlin/testing/IntIdentityMapper.kt index 4b0b4083..02bd371a 100644 --- a/testing/src/main/kotlin/testing/IdentityMapper.kt +++ b/testing/src/main/kotlin/testing/IntIdentityMapper.kt @@ -2,6 +2,6 @@ package testing import tech.mappie.api.Mappie -object IdentityMapper : Mappie() { +object IntIdentityMapper : Mappie() { override fun map(from: Int): Int = mapping() } \ No newline at end of file diff --git a/testing/src/main/kotlin/testing/IntToLongMapper.kt b/testing/src/main/kotlin/testing/IntToLongMapper.kt new file mode 100644 index 00000000..15372ee8 --- /dev/null +++ b/testing/src/main/kotlin/testing/IntToLongMapper.kt @@ -0,0 +1,9 @@ +package testing + +import tech.mappie.api.ObjectMappie + +data class LongInput(val value: Long) + +data class IntOutput(val value: Int) + +object IntToLongMapper : ObjectMappie() \ No newline at end of file diff --git a/testing/src/main/kotlin/testing/ListToNullableListMapper.kt b/testing/src/main/kotlin/testing/ListToNullableListMapper.kt index ddfd9d78..6b814266 100644 --- a/testing/src/main/kotlin/testing/ListToNullableListMapper.kt +++ b/testing/src/main/kotlin/testing/ListToNullableListMapper.kt @@ -14,4 +14,4 @@ object NullableListFromListMapper : ObjectMappie() { object StringIdentityMapper : ObjectMappie() { override fun map(from: String): String = from -} \ No newline at end of file +} diff --git a/testing/src/test/kotlin/testing/IdentityMapperTest.kt b/testing/src/test/kotlin/testing/IntIdentityMapperTest.kt similarity index 65% rename from testing/src/test/kotlin/testing/IdentityMapperTest.kt rename to testing/src/test/kotlin/testing/IntIdentityMapperTest.kt index e3c29fd7..8422337a 100644 --- a/testing/src/test/kotlin/testing/IdentityMapperTest.kt +++ b/testing/src/test/kotlin/testing/IntIdentityMapperTest.kt @@ -3,10 +3,10 @@ package testing import org.junit.jupiter.api.Test import kotlin.test.assertEquals -class IdentityMapperTest { +class IntIdentityMapperTest { @Test fun `map Int to Int via IdentityMapper`() { - assertEquals(1, IdentityMapper.map(1)) + assertEquals(1, IntIdentityMapper.map(1)) } } \ No newline at end of file diff --git a/testing/src/test/kotlin/testing/IntToLongMapperTest.kt b/testing/src/test/kotlin/testing/IntToLongMapperTest.kt new file mode 100644 index 00000000..56a02b9a --- /dev/null +++ b/testing/src/test/kotlin/testing/IntToLongMapperTest.kt @@ -0,0 +1,15 @@ +package testing + +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals + +class IntToLongMapperTest { + + @Test + fun `map Int to Long via IntToLongMapper`() { + assertEquals( + IntOutput(1), + IntToLongMapper.map(LongInput(1)), + ) + } +} \ No newline at end of file