shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

Arithmetic context always thinks arrays are indexed, not associative

Open koalaman opened this issue 9 years ago • 1 comments

For bugs

  • Rule Id (if any, e.g. SC1000): SC2154
  • My shellcheck version (shellcheck --version or "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.

koalaman avatar Sep 12 '17 23:09 koalaman

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?

Dar13 avatar Apr 01 '20 22:04 Dar13