kosi-libs / MocKMP

A mocking processor for Kotlin Multiplatform
https://kosi-libs.org/mockmp
MIT License
189 stars 12 forks source link

Invalid mock generation for functions with typealiased return types #34

Closed xpathexception closed 1 year ago

xpathexception commented 2 years ago
typealias SampleIntKeyMap<T> = Map<Int, T>

interface Sample {
    fun sample(): SampleIntKeyMap<String>
}

Generated mock implemenation for this sample has invalid type T as Map#value type:

import org.kodein.mock.Mocker

internal class MockSample(
    private val mocker: Mocker,
) : Sample {
    public override fun sample(): Map<Int, T> = this.mocker.register( //<=== Map<Int, String> or SampleIntKeyMap<String> is expected
        receiver = this,
        method = "sample()"
    )

    public override fun toString(): String = this.mocker.register(
        receiver = this,
        method = "toString()",
        default = { super.toString() }
    )
}
SalomonBrys commented 2 years ago

This is an issue with KSP: https://github.com/google/ksp/issues/1011

While waiting for it to be resolved, I can only recommend not using generic type aliases. I'll leave this open while waiting for KSP to solve the aforementioned issue.

ankushg commented 2 years ago

@SalomonBrys looks like the issue was closed in KSP!

SalomonBrys commented 1 year ago

@ankushg We're now waiting for the next version of Kotlin Poet, which will integrate this PR that fixes the same issue on Kotlin Poet.

Current Kotlin Poet version is 1.12.0 and does not embed this fix.

We still need to wait 😞.

afonsograca commented 1 year ago

Hi @SalomonBrys I believe Kotlin Poet has just released 1.13.0. Would that version work?