develooper Front page | perl.perl5.porters | Postings from October 2008

Re: Why are "Scalar value better written as" warnings not thrown for arrayrefs?

Thread Previous
Rafael Garcia-Suarez
October 31, 2008 07:58
Re: Why are "Scalar value better written as" warnings not thrown for arrayrefs?
Message ID:
2008/10/31 Chas. Owens <>:
> On Fri, Oct 31, 2008 at 09:13, Rafael Garcia-Suarez
> <> wrote:
>> 2008/10/31 Chas. Owens <>:
>>> I noticed today that no warning is thrown when a reference is used in
>>> a slice of one element, is there a reason for this?  I tested with
>>> both 5.8.8 and 5.10.0.
>> Because in the @a[0] case, the tokenizer is able to see the whole @a
>> expression, and check some heuristics to throw the warning, while in
>> the @{$ref}[0] case, the parser is called to parse what's in the
>> braces.
>> As many syntax warnings, they're only heuristics.
>> Example of another way to fool the warning: @a[q/0/].
>> --
>> #11953 Bien sûr, ce n'est qu'une heuristique, ce qui veut dire plus
>> prosaïquement que ça ne marche pas.
> I understand that the parser can't know what is between the braces,
> but isn't the fact that it sees @{anything at all}[0] enough to throw
> the warning?  Is there a valid "anything at all" that doesn't deserve
> the warning?

Actually the parser has nothing to do with the warning: it's the
tokenizer that emits it, as stated in my previous post.

It should be possible to move the warning somewhere in the optree
checker, probably by introducing a ck function for the hslice and
aslice ops. However that would need some work to get all the cases
right; and I think that writing a full ck function only for the
purpose of a warning is overkill, at it slows down compilation.

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About