This curried version works fine. Link to Scastie View code in action
def foo(a: Int)(b: Int = a-1): Int = a + b
foo(9)()
But this version throws the Error not found value a. Link to Scastie. View code in action
def bar(a: Int, b: Int = a-1): Int = a+b
bar(9)
Is this an actual error or is there any reason why it is not working?
fooworks because the 1st group, i.e. thea, is evaluated before the 2nd group, theb. Thebarwon't compile becauseahasn't been evaluated before it is referenced,a-1.