From: Joshua ben Jore Date: Wed, 1 Mar 2006 01:14:14 +0000 (-0600) Subject: Re: Patch lint for grep { /.../ } and grep /.../, X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3ee1325fce9723c5c1ae0ef2ad7307ce32571c1b;p=p5sagit%2Fp5-mst-13.2.git Re: Patch lint for grep { /.../ } and grep /.../, From: "Joshua ben Jore" Message-ID: p4raw-id: //depot/perl@27353 --- diff --git a/ext/B/B/Lint.pm b/ext/B/B/Lint.pm index 58015b9..05110bf 100644 --- a/ext/B/B/Lint.pm +++ b/ext/B/B/Lint.pm @@ -1,6 +1,6 @@ package B::Lint; -our $VERSION = '1.04'; +our $VERSION = '1.05'; =head1 NAME @@ -280,7 +280,12 @@ sub B::UNOP::lint { sub B::PMOP::lint { my $op = shift; if ($check{implicit_read}) { - if ($op->name eq "match" && !($op->flags & OPf_STACKED)) { + if ($op->name eq "match" + and not ( $op->flags & OPf_STACKED + or join( " ", + map $_->name, + @{B::parents()} ) + =~ /^(?:leave )?(?:null )*grep/ ) ) { warning('Implicit match on $_'); } } diff --git a/ext/B/t/lint.t b/ext/B/t/lint.t index d5ee215..01bee1b 100644 --- a/ext/B/t/lint.t +++ b/ext/B/t/lint.t @@ -16,7 +16,7 @@ BEGIN { require 'test.pl'; } -plan tests => 16; # adjust also number of skipped tests ! +plan tests => 18; # adjust also number of skipped tests ! # Runs a separate perl interpreter with the appropriate lint options # turned on @@ -43,6 +43,10 @@ runlint 'implicit-read', '/foo/', <<'RESULT'; Implicit match on $_ at -e line 1 RESULT +runlint 'implicit-read', 'grep /foo/, ()', ''; + +runlint 'implicit-read', 'grep { /foo/ } ()', ''; + runlint 'implicit-write', 's/foo/bar/', <<'RESULT'; Implicit substitution on $_ at -e line 1 RESULT