From c3eb04af9561cf842cfb6128b407e048c1778a49 Mon Sep 17 00:00:00 2001 From: stefankoppier Date: Wed, 26 Jun 2024 09:22:35 +0200 Subject: [PATCH] Improved error message --- .../mappie/resolving/classes/ObjectMappingBodyCollector.kt | 3 ++- .../tech/mappie/resolving/classes/ObjectMappingSource.kt | 1 + .../kotlin/tech/mappie/validation/MappingValidation.kt | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler-plugin/src/main/kotlin/tech/mappie/resolving/classes/ObjectMappingBodyCollector.kt b/compiler-plugin/src/main/kotlin/tech/mappie/resolving/classes/ObjectMappingBodyCollector.kt index 65fe4c68..1505a7db 100644 --- a/compiler-plugin/src/main/kotlin/tech/mappie/resolving/classes/ObjectMappingBodyCollector.kt +++ b/compiler-plugin/src/main/kotlin/tech/mappie/resolving/classes/ObjectMappingBodyCollector.kt @@ -80,7 +80,8 @@ private class ObjectBodyStatementCollector( target to ExpressionSource( dispatchReceiverSymbol, source, - (source.type as IrSimpleType).arguments[1].typeOrFail + (source.type as IrSimpleType).arguments[1].typeOrFail, + expression, ) } IDENTIFIER_TRANFORM -> { diff --git a/compiler-plugin/src/main/kotlin/tech/mappie/resolving/classes/ObjectMappingSource.kt b/compiler-plugin/src/main/kotlin/tech/mappie/resolving/classes/ObjectMappingSource.kt index a4eb1627..5fd9dec3 100644 --- a/compiler-plugin/src/main/kotlin/tech/mappie/resolving/classes/ObjectMappingSource.kt +++ b/compiler-plugin/src/main/kotlin/tech/mappie/resolving/classes/ObjectMappingSource.kt @@ -36,6 +36,7 @@ data class ExpressionSource( val extensionReceiverSymbol: IrValueSymbol, val expression: IrFunctionExpression, val type: IrType, + val origin: IrExpression?, ) : ObjectMappingSource { override fun resolveType() = type } diff --git a/compiler-plugin/src/main/kotlin/tech/mappie/validation/MappingValidation.kt b/compiler-plugin/src/main/kotlin/tech/mappie/validation/MappingValidation.kt index 5f7b4cb4..2ac46bf3 100644 --- a/compiler-plugin/src/main/kotlin/tech/mappie/validation/MappingValidation.kt +++ b/compiler-plugin/src/main/kotlin/tech/mappie/validation/MappingValidation.kt @@ -11,6 +11,7 @@ import tech.mappie.util.location import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.ir.IrFileEntry import org.jetbrains.kotlin.ir.types.getClass +import tech.mappie.resolving.classes.ExpressionSource data class Problem( val description: String, @@ -56,7 +57,11 @@ interface MappingValidation { .filter { (target, sources) -> !target.type.isAssignableFrom(sources.single().resolveType()) } .map { (target, sources) -> Problem.error( "Target ${mapping.targetType.getClass()!!.name.asString()}.${target.name.asString()} has type ${target.type.pretty()} which cannot be assigned from type ${sources.single().resolveType().pretty()}", - (sources.single() as? PropertySource)?.origin?.let { location(file, it) } + when (val source = sources.single()) { + is PropertySource -> source.origin?.let { location(file, it) } + is ExpressionSource -> source.origin?.let { location(file, it) } + else -> null + } ) } )