Skip to content

[BUG] Target with generic typed property does not know what type it is #195

@mfp-benerickson

Description

@mfp-benerickson

Describe the bug
Class with a generically typed property throws a compilation error when mapped to

To Reproduce

data class FooDto(
    val id: String,
    val name: String,
    val description: String
)

data class Foo(
    val uniqueId: String,
    val name: String,
    val description: String
)

data class Wrapper<W>(
    val wrapped: W,
    val name: String
)

object FooMapper : ObjectMappie<FooDto, Foo>() {
    override fun map(from: FooDto): Foo = mapping {
        to::uniqueId fromProperty from::id
    }
}

object WrapperMapper : ObjectMappie<FooDto, Wrapper<Foo>>() {
    override fun map(from: FooDto): Wrapper<Foo> = mapping {
        to::wrapped fromValue FooMapper.map(from)
        to::name fromProperty from::name
    }
}

Throws error Target Wrapper<W>::wrapped of type W cannot be assigned from value of type Foo

Expected behavior
Code compiles and generic typed property can be mapped to a value of the correct type

Kotlin version
2.1.20

Mappie version
2.1.20-1.2.1

Mappie and Kotlin compatibility
yes

Invocation method
Gradle 8.12.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions