2.2.0-RC1 - @Monitor handles interface implementations and constructor arguments wrong
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
- Pull my forked repository and open the example-cmp project.
- Build the project
- 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
Also forgot to mention that the bug is reproducable with either KSP 1 and 2.
How was this not fixed before the stable release?
@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?
Just checked... still not fixed in 2.2.0...
Let me check 👍