Happy New Year everybody, I have surprising issue ...
# ktor
i
Happy New Year everybody, I have surprising issue (code compiles!) with reified function in Ktor (Kotlin 1.6.10, Ktor 1.6.7, jvmTarget = “1.8”): https://gist.github.com/ikolomiets/689519a10f6f0a289a2ab2c06df710c1
Copy code
@Serializable
data class Age(val value: Int)

@Serializable
data class Update<T>(val old: T, val new: T)

fun main() {
    embeddedServer(Netty, port = 8080) {
        install(ContentNegotiation) {
            json()
        }
        routing {
            update<Age>()
        }
    }.start(wait = true)
}

inline fun <reified T> Route.update() {
    post("/") {
        val update = call.receive<Update<T>>()
        <http://application.log.info|application.log.info>("XXX update={}", update)
        call.respond(HttpStatusCode.OK, "OK")
    }
}
Trying
Copy code
% curl -v -H "Content-Type: application/json" -POST <http://localhost:8080/|http://localhost:8080/> -d '{"old":{"value":1},"new":{"value":2}}'
makes Ktor throw:
Copy code
java.lang.UnsupportedOperationException: This function has a reified type parameter and thus can only be inlined at compilation time, not called directly.
I found similar issue https://youtrack.jetbrains.com/issue/KTOR-582 that was identified as Kotlin compiler’s issue and eventually resolved as Fixed. Could this be regression with Kotlin compiler again? If not, can somebody advise how to avoid this exception? My project really needs such generic
Route.update()
function. Thank you!
a
Could you please file a separate issue?
👌 1
i