A use case for contextual parameters mixed with overloads is currently not possible.
def f(x: Int) = "a"
def f(x: (n: Int) ?=> Int) = "b"
f(10) // "a" - selects the first overload
f(n * 3) // error - Not found 'n'
I didn’t expect this result. I expected f(n * 3) = "b". I think it would be reasonable for the compiler to assume the first overload in the absence of any occurence of n, but select the second overload when n is in the expression.
They must be overloads, because in my use cases it is important that the base function has different behavior.
This behavior stems from how overload resolution and contextual parameter inference work separately in Scala. The compiler doesn’t infer n as contextual just from its use in f(n * 3) unless a context for n is already available. Since no given is in scope, it errors out.
To support your use case, you could explicitly provide a context or refactor to use inline or given instances where needed. Overload resolution currently doesn’t trigger contextual inference automatically.
This is a known limitation, and your suggestion could be a valid feature enhancement for Scala’s contextual overload resolution. Consider raising it on the Scala issue tracker for discussion.