As we know, you can pass operators directly to functions like this:
func foo(_ x: (Int, Int) -> Int) {
}
foo(+)
However, when I tried to do this in an assignment context, it doesn't work:
let f: (Int, Int) -> Int = +
It gives two errors:
Expected initial value after '='
Unary operator cannot be separated from its operand
I worked out that I have to do:
let f: (Int, Int) -> Int = (+)
How exactly does Swift parse each of these cases, allowing me to omit brackets in one case, but not the other?
Note that I'm not asking about the rationale behind Swift being designed this way. I'm just asking about the grammar production rules that produces this behaviour.
On Swift.org, I've been able to find this production rule that says operators are function call arguments:
function-call-argument → operator | identifier ':' operator
However, I've not been able to find production rules for (+). I started with "parenthesised expressions", which is a pair of parentheses surrounding an "expression". but "operator" is apparently not a kind of "expression".