mvdan syntax: better error when using "function" in POSIX mode
25abe06 Jul 13, 2023
syntax: better error when using "function" in POSIX mode
When parsing in POSIX mode, we already gave a good error message
when a user used the "function foo()" Bash syntax:

    $ shfmt -p <<<'function foo() { bar; }'
    <standard input>:1:13: the "function" builtin exists in bash; tried parsing as posix

However, our heuristic depended on the opening parenthesis token,
so it didn't work without the parentheses, which is valid Bash:

    $ shfmt -p <<<'function foo { bar; }'
    <standard input>:1:21: "}" can only be used to close a block

This "can only be used to close a block" error was rather confusing,
and caused multiple users to file bugs thinking the parser was at fault.
We now catch this other common pitfall pattern as well:

    $ shfmt -p <<<'function foo { bar; }'
    <standard input>:1:14: the "function" builtin is a bash feature; tried parsing as posix

We add the logic to the bit of code that handles each call argument,
but there shouldn't be a noticeable impact to most users
since it only kicks in when we're parsing in POSIX mode
and the current argument is a simple "{" literal.

Fixes #993.
25abe06