Hi :wave: been trying out K2 mode in my ktor proje...
# intellij
j
Hi šŸ‘‹ been trying out K2 mode in my ktor project, but it's breaking the imports when optimizing imports. It's removing these imports on files with routes, breaking the
post
and
put
routes. Is this a known issue?
r
Hi! Please share your IDEA version, and also how exactly the code is being broken Is there a different `post`/`put` function that is being preferred without an explicit import? A small reproducer would be really appreciated šŸ™
j
Hi @Roman Golyshev, thanks for the reply, here's the info: > Please share your IDEA version
IntelliJ IDEA 2024.3 (Ultimate Edition)
Build #IU-243.21565.193, built on November 13, 2024
> A small reproducer would be really appreciated šŸ™ Turns out it's pretty simple to reproduce:
Copy code
import io.ktor.resources.*
import io.ktor.server.resources.*
import io.ktor.server.routing.*

@Resource("/test")
class TestResource

fun Route.testRouting() {
    post<TestResource> {
        TODO()
    }
}
Error:
Copy code
Debug.kt:9:5 Overload resolution ambiguity between candidates:
fun <reified T : Any> Route.post(noinline body: suspend RoutingContext.(T) -> Unit): Route
fun <reified R : Any> Route.post(crossinline body: suspend RoutingContext.(R) -> Unit): Route
Adding
import io.ktor.server.resources.post
to that code fixes the error, but K2 will remove that import, while K1 keeps it there. PS: Tested in kotlin 2.1 and 2.0
r
Thank you for the quick response and the reproducer! AFAIU this issue was already fixed as a part of KTIJ-30991 It should be available in one of the bugfix releases in 243
šŸ‘ 1
j
Perfect, thanks! šŸ™‚
šŸ¤ 1