shellcheck
shellcheck copied to clipboard
Arithmetic context always thinks arrays are indexed, not associative
For bugs
- Rule Id (if any, e.g. SC1000): SC2154
- My shellcheck version (
shellcheck --versionor "online"): online - [x] I tried on shellcheck.net and verified that this is still a problem on the latest commit
- [ ] It's not reproducible on shellcheck.net, but I think that's because it's an OS, configuration or encoding issue
Here's a snippet or screenshot that shows the problem:
#!/bin/bash
declare -A array
(( array[key] ))
Here's what shellcheck currently says:
Line 3: (( array[key] )) ^-- SC2154: key is referenced but not assigned.
Here's what I wanted or expected to see:
Nothing. The array is declared as associative, so this is not an arithmetic context.
I ran into this on an older version (0.3.8 from EPEL 7) today, but the online version and 0.7.0 no longer prints the warning. Has this issue been fixed, or does it just need a new example?