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: arnold
Subject: Re: Why 'statement may have no effect' lint warning here?
Date: Mon, 12 Apr 2021 01:59:05 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Hi.

Arkadiusz Drabczyk <arkadiusz@drabczyk.org> wrote:

> The following code produces 'statement may have no effect' when run
> with --lint:
>
> BEGIN {
>     var = 1
>     var == 1 && var = 2
>     print "var ==", var
> }

I think that it's a bug that it does so.  The intent for that
warning is soemthing like:

BEGIN {
        var = 1
        var == 2        # no effect
}

> But if function call is used instead of 'var == 1' the warning is
> gone:
>
> BEGIN {
>     var = 1
>     print("hi") && var = 3
>     print "var ==", var
> }

I need to investigate this further.  In particular, none of gawk,
mawk or Unix nawk execute the print statement.   Technically,
print isn't a function, it doesn't return a value.  But none of the
three issue an error message about its use in an expression.

> I don't understand why is this warning issued in the first case. I
> thought that 'var == 1' will always have an effect as it returns
> either true or false but warning says something completely
> different. What is meant by 'effect' here?

See above; if `var == 1' is used standalone as a statement,
it has no effect -- nothing is changed as result.

I will investigate further.

Thanks,

Arnold



reply via email to

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