I encountered a weird behavior when using context ...
# language-evolution
m
I encountered a weird behavior when using context receivers, the following function definition results in long compiler errors:
Copy code
context(Transaction)
suspend inline fun <reified R: ResourceDTO, reified M : ResourceModel<R>>
    PipelineContext<*, ApplicationCall>.restoreOneDeletedResource(
    dao: ResourceDAOWithHistory<R, M>,
    ignoreWarningsParameter: String,
    changeLogParameter: String,
    historyIdParameterName: String
): CreateUpdateResult<R> { ... }
Error (I think the relevant part of the very long error message)
Caused by: java.lang.IllegalArgumentException: No argument for parameter VALUE_PARAMETER name:historyIdParameterName index:4 type:kotlin.String:
When I move the Transaction context to the function parameters and use with(transaction) inside the function, it works. Interestingly enough, the following related function gives no errors:
Copy code
context(Transaction)
suspend inline fun <reified R: ResourceDTO, reified M : ResourceModel<R>>
    PipelineContext<*, ApplicationCall>.createResource(dao: ResourceDAO<R, M>,
                                                       ignoreWarningsParameter: String,
                                                       changeLogParameter: String
): CreateUpdateResult<R> {
I would assume this is just a bug related to the fact context receivers are not stable and I am using every possible way to annoy the compiler (suspend, inline etc.)?
m
I would assume this is just a bug related to the fact context receivers are not stable and I am using every possible way to annoy the compiler (suspend, inline etc.)?
Yes. Context receivers have a lot of bugs when combined with other language features.
m
Yeah I thought so, had more problems with inherited extension functions as well (sadly no compile time error, it just could not find the function at runtime). But when you know the limitations, it already pretty great imo