Subject: | Bogus warning about scalar context when returning an array |
B::Lint warns about "Implicit scalar context for array in return"
This isn't true. The context isn't known at compile time. It's also not doing
what the documentation says that it's doing, which is reporting on things that
would be better written with an explicit C<scalar>. As this code is meant to
be making a list return.
So a factually correct message would state that it's unknown context. In which
case, it misses some, depending on whether the variable is lexical or package:
nc@I34 B-Lint-1.17$ perl -Mblib -MO=Lint -e 'sub foo {return @result;}'
Implicit scalar context for array in return at -e line 1
-e syntax OK
nc@I34 B-Lint-1.17$ perl -Mblib -MO=Lint -e 'my @result; sub foo {return @result;}'
-e syntax OK
But it always warns if a deference is involved:
nc@I34 B-Lint-1.17$ perl -Mblib -MO=Lint -e 'my $result; sub foo {return @$result;}'
Implicit scalar context for array in return at -e line 1
-e syntax OK
nc@I34 B-Lint-1.17$ perl -Mblib -MO=Lint -e 'sub foo {return @$result;}'
Implicit scalar context for array in return at -e line 1
-e syntax OK
However, it would be more useful if it didn't warn on an intentional return of
an array, when asked to report on something else (implicit context, that could
be fixed with the scalar operator)
I have no idea how to fix this. Sorry.
Nicholas Clark