Describe the bug
-S compgen option causes _variables function fail for ${array[index (lines 683-684):
COMPREPLY+=($(compgen -W '$(printf %s\\n "${!'${BASH_REMATCH[2]}'[@]}")' \
-P "${BASH_REMATCH[1]}${BASH_REMATCH[2]}[" -S ']}' -- "${BASH_REMATCH[3]}"))
Without -S everything works fine.
To reproduce
We can reproduce this behavior interactively inside Bash without _variables function:
declare -A assoc=([aa]=1 [ab]=2)
[[ '${assoc[a' =~ ^(\$\{[#\!]?)([A-Za-z0-9_]*)\[([^]]*)$ ]]
e $(compgen -W '$(printf %s\\n "${!'${BASH_REMATCH[2]}'[@]}")' -P "${BASH_REMATCH[1]}${BASH_REMATCH[2]}[" -S ']}' -- "${BASH_REMATCH[3]}")
- See problem

Expected behavior
No error expected even with failglob enabled.
Versions (please complete the following information)