bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Missing lint warning ?


From: Manuel Collado
Subject: Re: [bug-gawk] Missing lint warning ?
Date: Thu, 08 Aug 2013 16:22:51 +0200
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/17.0 Thunderbird/17.0

El 08/08/2013 7:47, Hermann Peifer escribió:

Hi,

I just noted that in the below test code, `print undefined' generates a
lint warning, whereas `x(undefined)' doesn't. Maybe this is a feature
rather than a small bug.

Probably a feature. A function argument can be a array to be assigned (output argument). So it is perfectly normal to pass an uninitialized one.

The fact that the argument is an array instead of a scalar is determined when the function call is actually executed. Example:

function y(a, b) {
   if (a) {
      b[1] = 1
      print "b is an array"
   } else {
      b = 1
      print "b is a scalar"
   }
}

So the lint checker cannot determine if the uninitialized argument of the function call is intended to be an array or a scalar without actually executing the program.

Regards.

In any case, I found it worth reporting.

Hermann

$ cat test.awk
BEGIN { print undefined ; x(undefined) }

function x(a)
{
     if (a == "" && a == 0) {
         print "*** argument 'a' has not been given ***"
     }
}


$ gawk --lint -f test.awk
gawk: test.awk:1: warning: reference to uninitialized variable `undefined'

gawk: test.awk:5: warning: reference to uninitialized argument `a'
gawk: test.awk:5: warning: reference to uninitialized argument `a'
*** argument 'a' has not been given ***


--
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado




reply via email to

[Prev in Thread] Current Thread [Next in Thread]