This valid bash snippet fails to parse because of the last line. The Workaround is simple (use quotes), but it is valid and I encountered it in the wild, so it should probably parse.
Tree-Sitter and whatever shellcheck uses internally parse the code correctly.
#!/bin/bash
declare -A things=( ["FOO"]=41 ["FOO BAR"]=42 )
declare foo=FOO
declare bar=BAR
echo "${things[$foo]}" # Works
echo "${things["$foo $bar"]}" # Works
echo "${things[$foo $bar]}" # Doesn't work
Running shfmt on this snippet causes an error. I'm using shfmt 3.8.0.
Edit: No, the bash tree-sitter grammar also parses it incorrectly.
This valid bash snippet fails to parse because of the last line. The Workaround is simple (use quotes), but it is valid and I encountered it in the wild, so it should probably parse.
Tree-Sitter and whatever shellcheck uses internally parse the code correctly.
Running
shfmt
on this snippet causes an error. I'm using shfmt 3.8.0.Edit: No, the bash tree-sitter grammar also parses it incorrectly.