bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] gawk's PROCINFO["identifiers"] fails to report type


From: arnold
Subject: Re: [bug-gawk] gawk's PROCINFO["identifiers"] fails to report type
Date: Mon, 17 Jul 2017 11:47:48 -0600
User-agent: Heirloom mailx 12.4 7/29/08

Manuel is correct. Awk is a dynamic language and its possible for
the same identifier to morph at runtime into either a scalar or
an array.

It might be possible to do a little bit stronger typing during parsing,
but I think it'd be risky and likely to break things.

I'm not up to adding full dataflow analysis to gawk, nor do I think it'd
be worth the trouble.

Thanks,

Arnold

Manuel Collado <address@hidden> wrote:

> What you want, i.e. to have the current type information at run-time, 
> will be available in the next gawk release as a builtin typeof(variable) 
> function. Please build from the master GIT sources to test it.
>
> The current gawk-4.1.4 only has an isarray(variable) built-in function 
> that discriminates between arrays and scalars.
>
> HTH.
>
> El 17/07/2017 a las 13:37, Peter Backes escribi?:
> > Hello,
> >
> > This was originally reported at
> > https://bugzilla.redhat.com/show_bug.cgi?id=1471421
> >
> > Description of problem:
> > when asking AWK for the type of an array variable, it incorrectly
> > claims that it is untyped.
> >
> > Version-Release number of selected component (if applicable):
> > gawk-4.1.3-8.fc25.i686
> >
> > How reproducible:
> > always
> >
> > Steps to Reproduce:
> > 1. gawk 'BEGIN { testx["bla"]="foo";testx["bla2"]="foo2";print
> > PROCINFO["identifiers"]["testx"]; split("cul-de-sac",a,"-",seps); print
> > PROCINFO["identifiers"]["a"],PROCINFO["identifiers"]["seps"];}'
> >
> > Actual results:
> > untyped
> > untyped untyped
> >
> > Expected results:
> > array
> > array array
> >
> > Additional info:
> > Same behavior actually for numbers and strings:
> >
> > % gawk 'BEGIN { x="test"; print PROCINFO["identifiers"]["x"];}'
> > untyped
> > % gawk 'BEGIN { x=5.5; print PROCINFO["identifiers"]["x"];}'
> > untyped
> >
> > Perhaps it is because "The values indicate what gawk knows about the
> > identifiers after it has finished parsing the program; they are not
> > updated while the program runs"
> > (https://www.gnu.org/software/gawk/manual/gawk.html)? Although I still
> > think it's a bug. In the examples given, the type IS statically known
> > after parsing. Because the respective identifiers are used in only one,
> > unique type of context. 'testx["bla"]="foo"' clearly says that testx is
> > an array, and if there is no conflicting assignment (such as testx =
> > "xyz") afterwards or before, the type must be array. What purpose would
> > PROCINFO["identifiers"] have anyway, if it wouldn't handle this basic
> > case well?
> >
> > PROCINFO["identifiers"]["PROCINFO"] correctly reports "array".
> >
> > Best wishes
> > Peter Backes
> >
>
> -- 
> Manuel Collado - http://lml.ls.fi.upm.es/~mcollado
>




reply via email to

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