why if I use an unamed context parameter this isn'...
# getting-started
e
why if I use an unamed context parameter this isn't available for resolution?
Copy code
import org.gradle.api.Project
import java.io.ByteArrayOutputStream

context(_: Project)
operator fun String.invoke(vararg args: String): String {
    val output = ByteArrayOutputStream()
    providers.exec { // error, `providers` unresolved
        commandLine("arduino-cli", "version")
        standardOutput = output
    }
    return output.toString()
}
if I use the named one, then it's fine
Copy code
import org.gradle.api.Project
import java.io.ByteArrayOutputStream

context(project: Project)
operator fun String.invoke(vararg args: String): String {
    val output = ByteArrayOutputStream()
    project.providers.exec {
        commandLine("arduino-cli", "version")
        standardOutput = output
    }
    return output.toString()
}
y
Simple: make a bridge function/property:
Copy code
context(p: Project) val providers get() = p.providers
e
but why? Shouldnt this work out of the box?
Copy code
public interface Project { 

    ProviderFactory getProviders();
y
It's an intentional change. It's to prevent scope pollution by context parameters. You have to explicitly make these bridge methods if you deem them fit. Btw, you can also do:
contextOf<Project>().providers.exec
instead of making a bridge method
e
but the docs say so:
You can use
_
as a context parameter name. In this case, the parameter's value is available for resolution but is not accessible by name inside the block:
or am I getting it wrong?
y
It's available for resolution as a context parameter, not as a receiver. This was the biggest change between context receivers and context parameters
👍 1