bug-gawk
[Top][All Lists]
Advanced

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

Re: parameter type is incorrectly reported by typeof()


From: arnold
Subject: Re: parameter type is incorrectly reported by typeof()
Date: Mon, 15 Nov 2021 20:56:50 -0700
User-agent: Heirloom mailx 12.5 7/5/10

Hi.

Thank you for the report. Gawk is working correctly here, there is
no bug.  The 'c' parameter in the _c() function receives its type
dynamically, at run time, based on its first actual usage. The awk
language has always behaved this way.

I am fairly sure that this is documented in the manual.

Arnold

P.S. The current version of gawk is 5.1.1, you should upgrade.

Denis Shirokov <cosmogen@gmail.com> wrote:

> hello
>
> found the following issue:
>
> parameter type is incorrectly reported by typeof():
>
> let's see on to example below:
>
> BEGIN{
>
>       _a()        # define parameter as unassigned
>
>       mode = 1
>
>       print; print; print
>
>       _a()        # define parameter as an array
>
>       }
>
> func  _a( a ) {
>
>       print "a: " typeof( a )
>
>       _b( a )
>
>       print "a: " typeof( a ) }
>
>       func _b( b ) {
>
>             _c( b )
>
>             print "b: " typeof( b ) }
>
>                   func  _c( c, x ) {
>
>                         if ( mode )
>
>                               "" in c
>
>                         else  x = c
>
>                         print "c: " typeof( c ) }
>
> output:
>
>       D:\CPU\DEV\GAWK\REPORT\5\typeof>gawk -b -s -f ./typeof.gwk
>       a: untyped
>       c: untyped
>       b: untyped
>       a: unassigned
>
>
>
>       a: untyped
>       c: array
>       b: array
>       a: array
>
> at the first time function _a() started the global var `mode' is false.
> so it's will test type `unassigned' auto definition:
>
> let's see on the results: at the enter of function _a() it's print the type
> of parameter as `untyped'. then _a() calls _b() and it's call _c()
> where parameter is forced to be unassigned. but the function _c() and _b()
> reports that parameter is still untyped. at the exit function _a() printing
> current type of parameter and it's correct: `unassigned'.
>
> the problem is in that function _b() is still remains that type of the 
> parameter
> is `untyped' and even function _c() - where type definition is
> performed it's still
> report that parameter is `untyped'.
>
> at the second time globvar `mode' is true so it's will test type `array'
> autodefinition.
> it's seems that there is no problems here.
>
>
> # GNU Awk 5.1.0, API: 3.0 (GNU MPFR 3.1.5, GNU MP 6.1.2)
> # Windows 10 x64
>
> Best Regards
> Denis



reply via email to

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