File tree Expand file tree Collapse file tree 4 files changed +37
-2
lines changed
main/kotlin/tech/mappie/ir
test/kotlin/tech/mappie/testing Expand file tree Collapse file tree 4 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,9 @@ import tech.mappie.ir.util.BaseVisitor
1616import tech.mappie.exceptions.MappiePanicException.Companion.panic
1717import tech.mappie.ir.resolving.MappieDefinition
1818import tech.mappie.ir.resolving.RequestResolverContext
19+ import tech.mappie.ir.util.isSubclassOf
20+ import tech.mappie.ir.util.mappieSuperType
21+ import tech.mappie.ir.util.mappieType
1922
2023// TODO: we should collect al publicly visible, and add those during resolving that are visible from the current scope.
2124class DefinitionsCollector (val context : MappieContext ) {
@@ -64,8 +67,10 @@ class ProjectMappieDefinitionsCollector(val context: MappieContext) : BaseVisito
6467 override fun visitClass (declaration : IrClass , data : Unit ) =
6568 buildList {
6669 if (context.shouldGenerateCode(declaration)) {
67- (declaration.superTypes.single() as ? IrSimpleType )?.let {
68- add(MappieDefinition (declaration))
70+ context(context) {
71+ declaration.mappieSuperType()?.let {
72+ add(MappieDefinition (declaration))
73+ }
6974 }
7075 }
7176 addAll(declaration.declarations.filterIsInstance<IrClass >().flatMap { it.accept(data) })
Original file line number Diff line number Diff line change @@ -21,9 +21,16 @@ import org.jetbrains.kotlin.ir.types.getClass
2121import org.jetbrains.kotlin.ir.util.SYNTHETIC_OFFSET
2222import org.jetbrains.kotlin.ir.util.isNullable
2323import org.jetbrains.kotlin.ir.util.erasedUpperBound
24+ import org.jetbrains.kotlin.ir.util.isStrictSubtypeOfClass
2425import org.jetbrains.kotlin.name.Name
26+ import tech.mappie.MappieContext
27+ import tech.mappie.referenceMappieClass
2528import tech.mappie.util.*
2629
30+ context (context: MappieContext )
31+ fun IrClass.mappieSuperType (): IrType ? =
32+ allSuperTypes().singleOrNull { it.isStrictSubtypeOfClass(context.referenceMappieClass()) }
33+
2734fun IrClass.isSubclassOf (clazz : IrClassSymbol ) =
2835 allSuperTypes().any { it.erasedUpperBound == clazz.defaultType.getClass()!! }
2936
Original file line number Diff line number Diff line change @@ -30,4 +30,26 @@ class MapperInheritanceTest : MappieTestCase() {
3030 .isEqualTo(Output (" test" ))
3131 }
3232 }
33+
34+ @Test
35+ fun `inherit with interface mapper should succeed` () {
36+ compile {
37+ file(" Mapper.kt" ,
38+ """
39+ import tech.mappie.api.ObjectMappie
40+ import tech.mappie.testing.MapperInheritanceTest.*
41+
42+ class Mapper : ObjectMappie<Input, Output>(), AutoCloseable {
43+ override fun close() { }
44+ }
45+ """
46+ )
47+ } satisfies {
48+ isOk()
49+ hasNoWarningsOrErrors()
50+
51+ assertThat(objectMappie<Input , Output >().map(Input (" test" )))
52+ .isEqualTo(Output (" test" ))
53+ }
54+ }
3355}
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ changelog:
99 - " Added support for kotlinx-datetime to JVM mappers, which can be imported via a separate dependency."
1010 - " Fixed check of runtime usage of of mapping DSL for multiple object mappie."
1111 - " [#264](https://github.com/Mr-Mappie/mappie/issues/264) Fix compilation error with ObjectMappie5."
12+ - " [#262](https://github.com/Mr-Mappie/mappie/issues/262) Fixed compilation error when mapper inherits from more than a Mappie subclass."
1213 - " Minor performance enhancements - by @ErwinOlie."
1314 - " Fix for missing reporting when both a mapper and its generated mapper have issues - by @ErwinOlie."
1415 - " Improved reporting of type parameters - by @ErwinOlie."
You can’t perform that action at this time.
0 commit comments