Comment

Comment by acqq

> this can be done with Python code too

Can it? That's what I would like to know, how to know without executing the code with the argument 4 that there's an error in this Python code:

  import sys;

  def f( x ):
    if x == 4:
      x += q
    print( x )

  f( int( sys.argv[1] ) )
That will "work" until 4 is passed at the runtime:

    $ ex-undefined.py 4
    Traceback (most recent call last):
      File "/tmp/ex-undefined.py", line 8, in <module>

        f( int( sys.argv[1] ) )
      File "/tmp/ex-undefined.py", line 5, in f
        x += q
    NameError: name 'q' is not defined
With this shell code

  #!/bin/sh
  f() {
    x=$1
    if [ "$x" = 4 ] ; then
      x=$((x+q))
    fi
    echo $x
  }
  f "$1"

and shellcheck I get:

   Line 5:
      x=$((x+q))
             ^-- SC2154: q is referenced but not assigned.
even if I have never executed the code.
parent acqq 6 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton