diff --git a/compiler-plugin/src/main/kotlin/tech/mappie/generation/MappieIrTransformer.kt b/compiler-plugin/src/main/kotlin/tech/mappie/generation/MappieIrTransformer.kt index 5f7e2c70..9ba7aaf4 100644 --- a/compiler-plugin/src/main/kotlin/tech/mappie/generation/MappieIrTransformer.kt +++ b/compiler-plugin/src/main/kotlin/tech/mappie/generation/MappieIrTransformer.kt @@ -13,11 +13,6 @@ import org.jetbrains.kotlin.ir.builders.* import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression -import org.jetbrains.kotlin.ir.expressions.IrPropertyReference -import org.jetbrains.kotlin.ir.types.IrSimpleType -import org.jetbrains.kotlin.ir.types.IrType -import org.jetbrains.kotlin.ir.types.classOrFail -import org.jetbrains.kotlin.ir.types.typeOrFail import org.jetbrains.kotlin.ir.util.* import tech.mappie.MappieIrRegistrar import tech.mappie.resolving.enums.ExplicitEnumMappingTarget @@ -34,7 +29,7 @@ class MappieIrTransformer(private val symbols: List) : IrEleme if (declaration.accept(ShouldTransformCollector(), Unit)) { var function = declaration.declarations .filterIsInstance() - .first { it.name == IDENTIFIER_MAP } + .first { it.name == IDENTIFIER_MAP && it.overriddenSymbols.isNotEmpty() } if (function.isFakeOverride) { declaration.declarations.removeIf { it is IrSimpleFunction && function.name == IDENTIFIER_MAP } diff --git a/compiler-plugin/src/test/kotlin/tech/mappie/testing/MapperClassCanMultipleMapFunctionsTest.kt b/compiler-plugin/src/test/kotlin/tech/mappie/testing/MapperClassCanMultipleMapFunctionsTest.kt new file mode 100644 index 00000000..7c3b4219 --- /dev/null +++ b/compiler-plugin/src/test/kotlin/tech/mappie/testing/MapperClassCanMultipleMapFunctionsTest.kt @@ -0,0 +1,57 @@ +package tech.mappie.testing + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.io.TempDir +import tech.mappie.testing.compilation.KotlinCompilation +import tech.mappie.testing.compilation.KotlinCompilation.ExitCode +import tech.mappie.testing.compilation.SourceFile.Companion.kotlin +import java.io.File + +class MapperClassCanMultipleMapFunctionsTest { + + data class Input(val text: String) + data class Output(val text: String, val int: Int) + + @TempDir + private lateinit var directory: File + + @Test + fun `mapper with multiple map functions should succeed`() { + KotlinCompilation(directory).apply { + sources = buildList { + add( + kotlin("Test.kt", + """ + import tech.mappie.api.ObjectMappie + import tech.mappie.testing.MapperClassCanMultipleMapFunctionsTest.* + + class Mapper(private val int: Int) : ObjectMappie() { + fun map(value: String) = value + + override fun map(from: Input) = mapping { + Output::int fromValue int + } + + fun map(value: Int) = int + } + """ + ) + ) + } + }.compile { + assertThat(exitCode).isEqualTo(ExitCode.OK) + assertThat(messages).isEmpty() + + val mapper = classLoader + .loadObjectMappieClass("Mapper") + .constructors + .first() + .call(10) + + assertThat(mapper.map(Input("test"))) + .isEqualTo(Output("test", 10)) + } + } + +} \ No newline at end of file