I'm messing around with the new context receivers ...
# getting-started
r
I'm messing around with the new context receivers and I'm seeing what appears to be an issue, but I figured I'd ask here to make sure I'm not just doing something wrong. (see thread)
If I have
Copy code
operator fun <T> T.invoke(action: context(T) () -> Unit) {
    action(this)
}
This works:
Copy code
val action: context(String) () -> Unit = {
    length
}
"Test"(action)
but inlining
action
does not:
Copy code
"Test" {
    length  // Unresolved reference: length
}
(The actual use case is of course a bit more complex, but that demonstrates the root issue.)
d
Please report an issue kotl.in/issue
👍 1
r
Done: https://youtrack.jetbrains.com/issue/KT-51941 I wasn't sure how to title it
y
This looks to be the same issue as KT-51243 I explained a workaround here, but TL;DR: rewrite it to be this:
Copy code
sealed interface TypeWrapper<out A> {
    object IMPL: TypeWrapper<Nothing>
}
operator fun <T> T.invoke(action: context(T) (TypeWrapper<T>) -> Unit) {
    action(this, TypeWrapper.IMPL)
}
👍 1