koin-annotations icon indicating copy to clipboard operation
koin-annotations copied to clipboard

2.2.0-RC1 - @Monitor handles interface implementations and constructor arguments wrong

Open HLCaptain opened this issue 7 months ago • 5 comments

Describe the bug While I wanted to integrate performance monitoring via @Monitor, I found several problems with the generated code.

The generated code does not handle generics well.

On build, I ran into the problem:

[ksp] --> Missing definition for 'clients : io.ktor.client.HttpClient' in 'com.jetbrains.kmpapp.data.KtorMuseumApi'. Fix by adding a definition annotation or function definition in module class.

I got the original problem with DataStore<Preferences>, but this is my example code:

// com/jetbrains/kmpapp/data/MuseumApi.kt

@Monitor
@Single
class KtorMuseumApi(
    private val clients: List<HttpClient>, // IMPORTANT: List<*> as the argument
) : MuseumApi {
    companion object {
        private const val API_URL =
            "https://raw.githubusercontent.com/Kotlin/KMP-App-Template/main/list.json"
    }

    override suspend fun getData(): List<MuseumObject> {
        return try {
            clients.first().get(API_URL).body()
        } catch (e: Exception) {
            if (e is CancellationException) throw e
            e.printStackTrace()

            emptyList()
        }
    }
}

// org/koin/ksp/generated/KtorMuseumApiProxycom$jetbrains$kmpapp$data.kt
/**
 * Generated by @Monitor - Koin proxy for 'KtorMuseumApi'
 * 
 * Automatically monitors all method calls and reports performance data to the Kotzilla Platform,
 * the official Koin platform tools (https://kotzilla.io).
 * Requires 'io.kotzilla:kotzilla-core' dependency.
 * 
 * @see <a href="https://doc.kotzilla.io">Documentation</a>
 * @see <a href="https://doc.kotzilla.io/docs/releaseNotes/changelogSDK">Latest Version</a>
 * @generated Do not modify - auto-generated class
 */
 // IMPORTANT Notice that the constructor argument here should be List<HttpClient>

class KtorMuseumApiProxy(clients : kotlin.collections.List) : com.jetbrains.kmpapp.data.KtorMuseumApi(clients) {
	override override suspend fun getData() : kotlin.collections.List<com.jetbrains.kmpapp.data.MuseumObject> { return KotzillaCore.getDefaultInstance().suspendTrace("KtorMuseumApi.getData") { super.getData() } }
}

The generated code does not handle allOpen correctly when implementing an interface

The same example above also gives the repeated override error. I suspect that overriding an already implemented function (with override) produces the problem.

To Reproduce

  1. Pull my forked repository and open the example-cmp project.
  2. Build the project
  3. Run into this problem: [ksp] --> Missing definition for 'clients : io.ktor.client.HttpClient' in 'com.jetbrains.kmpapp.data.KtorMuseumApi'. Fix by adding a definition annotation or function definition in module class.

Expected behavior The generated code for KtorMuseumApiProxy should look like this:

package org.koin.ksp.generated

import io.kotzilla.sdk.KotzillaCore

/**
 * Generated by @Monitor - Koin proxy for 'KtorMuseumApi'
 * 
 * Automatically monitors all method calls and reports performance data to the Kotzilla Platform,
 * the official Koin platform tools (https://kotzilla.io).
 * Requires 'io.kotzilla:kotzilla-core' dependency.
 * 
 * @see <a href="https://doc.kotzilla.io">Documentation</a>
 * @see <a href="https://doc.kotzilla.io/docs/releaseNotes/changelogSDK">Latest Version</a>
 * @generated Do not modify - auto-generated class
 */
class KtorMuseumApiProxy(clients : kotlin.collections.List<io.ktor.client.HttpClient>) : com.jetbrains.kmpapp.data.KtorMuseumApi(clients) {
	override suspend fun getData() : kotlin.collections.List<com.jetbrains.kmpapp.data.MuseumObject> { return KotzillaCore.getDefaultInstance().suspendTrace("KtorMuseumApi.getData") { super.getData() } }
}

Koin project used and used version (please complete the following information):

kotzilla = "1.2.1"
koin-annotations = "2.2.0-RC1"
koin = "4.1.0"
kotlin = "2.1.20"
# used the ktor3 version
kotzilla-sdk = { module = "io.kotzilla:kotzilla-sdk-ktor3", version.ref = "kotzilla" }

Additional moduleDefinition

HLCaptain avatar Sep 05 '25 11:09 HLCaptain

Also forgot to mention that the bug is reproducable with either KSP 1 and 2.

HLCaptain avatar Sep 05 '25 11:09 HLCaptain

How was this not fixed before the stable release?

JordanLongstaff avatar Oct 07 '25 13:10 JordanLongstaff

@arnaudgiuliani sorry for the ping, but I think this is quite critical not to be fixed in the prod released build. Any chance this gets fixed soon?

HLCaptain avatar Oct 08 '25 06:10 HLCaptain

Just checked... still not fixed in 2.2.0...

HLCaptain avatar Oct 08 '25 11:10 HLCaptain

Let me check 👍

arnaudgiuliani avatar Oct 20 '25 13:10 arnaudgiuliani