[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: parameter type is incorrectly reported by typeof()
From: |
Andrew J. Schorr |
Subject: |
Re: parameter type is incorrectly reported by typeof() |
Date: |
Mon, 15 Nov 2021 23:15:00 -0500 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hi,
I'm not sure there isn't something weird here, but I could be confused.
Consider the two attached test scripts using gawk-5.1-stable:
bash-4.2$ cat /tmp/test.awk
BEGIN {
print typeof(x)
y = x
print typeof(x)
}
bash-4.2$ ./gawk -f /tmp/test.awk
untyped
unassigned
bash-4.2$ cat /tmp/test1.awk
function f(x) {
print typeof(x)
y = x
print typeof(x)
}
BEGIN {
print typeof(x)
f(x)
}
bash-4.2$ ./gawk -f /tmp/test1.awk
untyped
untyped
untyped
So in the 2nd program, inside the function f, why doesn't assigning
'y = x' force x to have a scalar value and show as untyped instead
of unassigned as it does in the first program?
Regards,
Andy
On Mon, Nov 15, 2021 at 08:56:50PM -0700, arnold@skeeve.com wrote:
> 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
--
Andrew Schorr e-mail: aschorr@telemetry-investments.com
Telemetry Investments, L.L.C. phone: 917-305-1748
152 W 36th St, #402 fax: 212-425-5550
New York, NY 10018-8765
test.awk
Description: Text document
test1.awk
Description: Text document