Perl-Critic / PPI

54 stars 44 forks source link

QuoteLike::Words->literal returns wrong results after contents change #296

Open eldering opened 4 months ago

eldering commented 4 months ago

After changing the contents of a PPI::Token::QuoteLike::Words element with the set_contents method, it seems that the changed contents is not reparsed and internal meta-data not updated. This leads to a call to literal returning wrong results.

The below MWE program

#!/usr/bin/env perl

use v5.24;
use strict;
use warnings;
use Data::Dumper;

use PPI;

my $doc = PPI::Document->new(\q!my @a = qw( 1 2 3);!);

my $qw = $doc->find_first('PPI::Token::QuoteLike::Words');

print Dumper([ $qw->literal ], $qw);

$qw->set_content($qw->content =~ s/ 2//r);

print Dumper([ $qw->literal ], $qw);

first returns the tokens 1,2,3 as expected, but the second time returns 1 and 3).