Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive for var in code removed by inlining #10

Open
dolmen opened this issue Nov 14, 2014 · 0 comments
Open

False positive for var in code removed by inlining #10

dolmen opened this issue Nov 14, 2014 · 0 comments
Labels

Comments

@dolmen
Copy link
Contributor

dolmen commented Nov 14, 2014

Here is foo.pm:

package foo;
use strict;
use warnings;

use constant DEAD_CODE => 0;

sub test
{
    my $var;
    if (DEAD_CODE) {
        my $false_positive = 'xxx';    # <----- false positive
        bar($false_positive);
        $var = 'abc';
    } else {
        $var = 'def';
    }
}

1;

The $false_positive variable is in dead code that is removed by inlining as can be seen with B::Deparse:

$ perl -MO=Deparse foo.pm
package foo;
sub BEGIN {
    require strict;
    do {
        'strict'->import
    };
}
use constant ('DEAD_CODE', 0);
sub test {
    use warnings;
    use strict;
    my $var;
    do {
        $var = 'def'
    };
}
use warnings;
use strict;
'???';
foo.pm syntax OK

But Test::Vars reports $false_positive as an unused variable:

$ TEST_VERBOSE=1 perl -Ilib -MTest::Vars -E 'vars_ok(shift)' foo.pm
# checking foo in foo.pm ...
# $false_positive is used once in &foo::test 
not ok 1 - foo.pm
#   Failed test 'foo.pm'
#   at -e line 1.
# Tests were run but no plan was declared and done_testing() was not seen.
@jkeenan jkeenan added the Bug label Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants