Skip to content

Commit

Permalink
Improved error message
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankoppier committed Jun 26, 2024
1 parent d42edab commit c3eb04a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ data class ExpressionSource(
val extensionReceiverSymbol: IrValueSymbol,
val expression: IrFunctionExpression,
val type: IrType,
val origin: IrExpression?,
) : ObjectMappingSource {
override fun resolveType() = type
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
) }
)

Expand Down

0 comments on commit c3eb04a

Please sign in to comment.