Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid mock generation for functions with typealiased return types #34

Closed
xpathexception opened this issue Jul 20, 2022 · 4 comments
Closed

Comments

@xpathexception
Copy link

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() }
    )
}
@xpathexception xpathexception changed the title Invalid mock generation for functions with typealiases Invalid mock generation for functions with typealiased return types Jul 20, 2022
@SalomonBrys
Copy link
Member

This is an issue with KSP: google/ksp#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
Copy link
Contributor

ankushg commented Nov 4, 2022

@SalomonBrys looks like the issue was closed in KSP!

@SalomonBrys
Copy link
Member

SalomonBrys commented Dec 5, 2022

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants