bug-gawk
[Top][All Lists]
Advanced

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

Re: Why 'statement may have no effect' lint warning here?


From: Manuel Collado
Subject: Re: Why 'statement may have no effect' lint warning here?
Date: Wed, 14 Apr 2021 18:53:36 +0200
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0

El 14/04/2021 a las 7:16, arnold@skeeve.com escribió:
...
`a == 1 && b = 42' is not a mistake. It's semantically valid code.
It might be "poor" code by various standards, but it's valid and
the current lint warning for it is a bug.

Well, a semantically valid code may lead to several --lint warnings.

$ gawk --lint "BEGIN{ a == b && b = 42 }"
gawk: cmd. line:1: warning: statement may have no effect
gawk: cmd. line:1: warning: reference to uninitialized variable `a'
gawk: cmd. line:1: warning: reference to uninitialized variable `b'
gawk: cmd. line:1: warning: assignment used in conditional context

I assume only the first warning is under discussion.


However, gawk does not comment on the quality of the code it runs, even
with --lint. Were it to do so, there is code I've seen that should
brick the computer it runs on.

Rather, it does try to point out real semantic mistakes, such as

BEGIN {
        a = 5
        b = 3
        a + b   # useless statement
}

The current code in gawk that does this analysis and prints error messages
is a bit confused.  I think this became the case when gawk moved from its
original recursive parse tree evaluator to the current byte code engine.

I've had a quick look at the gawk source code, and see you are quite
right. As a last chance option the syntax tree could perhaps be rebuilt
by a code similar to the pretty-print in profile.c.


I am working to straighten this out and will eventually post a patch.
In the meantime, just accept that current gawk is not behaving
completely correctly in this area.

Agreed. Thanks for your invaluable work of gawk maintenance.

--
Manuel Collado - http://mcollado.z15.es



reply via email to

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