Hi! I get an IDE linting error in Android Studio w...
# functional
j
Hi! I get an IDE linting error in Android Studio when using the
context
method :
Copy code
val myDependency = Box<String>()
context(myDependency) {
    doWork()
}
doWork
has a red wave underline saying “No context argument for ‘BoxString’ found.” If I replace
context
with
with
the linting goes away. But I can compile my program without issues while using
context
, it’s just in the IDE. Any ideas how to fix that?
s
Just to clarify: what’s
context
? Is it context receivers/parameters?
j
Yes, I forgot to provides some first hehe.
Copy code
fun test() {
    val myDependency = Box<String>()
    context(myDependency) {
        doWork()
    }
}

context(myDependency: Box<String>)
fun doWork() {
    // do stuff with myDependency
}
d
Don't you mean:
Copy code
fun test() {
    val myDependency = Box<String>()
    with(myDependency) { // with, not context here
        doWork()
    }
}
⬆️ 1
j
with
works fine as long as I only need one dependency, but one does need
context
for more than one
My example should have two dependencies, true. (For some reason the Slack app doesn't let me edit the message)