bug-gawk
[Top][All Lists]
Advanced

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

Re: Lint warning when passing strnum to 'length'


From: arnold
Subject: Re: Lint warning when passing strnum to 'length'
Date: Tue, 22 Mar 2022 13:07:23 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Hi.

Please see the attached diff. I decided to go through all the
builtins and add or change lint checks, as appropriate.

Thanks,

Arnold

Timothy Sample <samplet@ngyro.com> wrote:

> Hello!
>
> While using ‘gawk --lint’ just now, I received many warnings:
>
>     warning: length: received non-string argument
>
> However, what I am passing is an “strnum”.  Even though the input string
> looks like a number, I’m happy to treat it like a string, which makes
> the lint warning net very useful to me.
>
> The following demonstrates the behaviour:
>
>     echo 123 | gawk --lint '{ print(length($1)); }'
>
> (BTW, this is on GNU Awk 5.1.0 from Guix.)
>
> There’s every possibility that this is intentional, but my naïve
> expectation is that Gawk should be okay with passing an strnum to
> ‘length’.  I am aware that I can suppress the warning by forcing Gawk to
> treat the input as a string (‘length($1 "")’), but I’m not sure I should
> have to.  Thoughts?
>
> In general, I am very impressed with the Gawk linter and also the
> “--posix” flag, which help me write cleaner, more portable Awk
> programs.  Thank you very much!
>
>
> -- Tim
>

Attachment: lint.diff
Description: Text document


reply via email to

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