This works due to Translation of Calls to Extension Methods. But new rules seem be ad-hoc and lacking some groundwork. While encoding of type classes looks great we are not restricted to use the feature only this way. In general I can extend the scope with a bunch of functions using implied parameters with extension methods. I can imagine someone will definitely find it useful while implementing DSL or just trying to cut some boilerplate.
trait Connection {
def (st: Statement) execute: Unit
}
def withConnection(f: given Connection => Unit) = f given new Connection {
def (st: Statement) execute = println(s"Executed $st")
}
withConnection {
"SELECT 1".execute
}
Why not go further and introduce scope manipulation as a separate feature so that all other use cases would be covered? For the reference the thread where this feature was discussed.