diff options
author | Father Chrysostomos <sprout@cpan.org> | 2010-09-20 22:05:34 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2010-09-20 22:05:34 -0700 |
commit | 2474a784a94d8c70aea9c330d9f2a902b8a68b85 (patch) | |
tree | b09595a0bb76d458489b7aee6fef31f7286c1c9e /t | |
parent | af9838cc2fa3350e15e88a27008899ae3a3afdb6 (diff) | |
download | perl-2474a784a94d8c70aea9c330d9f2a902b8a68b85.tar.gz |
[perl #20444] regex not evaluated in constant ?:
$text =~ ( 1 ? /phoo/ : /bear/)
used to be constant-folded to
$text =~ /phoo/
This patch solves the problem by marking match and subst ops as
OPf_SPECIAL during constant folding, so the =~ operator can tell not
to take possession of it.
Diffstat (limited to 't')
-rw-r--r-- | t/comp/fold.t | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/t/comp/fold.t b/t/comp/fold.t index 23e8e89b62..ec95f1aed8 100644 --- a/t/comp/fold.t +++ b/t/comp/fold.t @@ -4,7 +4,7 @@ # we've not yet verified that use works. # use strict; -print "1..13\n"; +print "1..19\n"; my $test = 0; # Historically constant folding was performed by evaluating the ops, and if @@ -52,6 +52,16 @@ sub is { failed($got, "'$expect'", $name); } +sub ok { + my ($got, $name) = @_; + $test = $test + 1; + if ($got) { + print "ok $test - $name\n"; + return 1; + } + failed($got, "a true value", $name); +} + my $a; $a = eval '$b = 0/0 if 0; 3'; is ($a, 3, 'constants in conditionals don\'t affect constant folding'); @@ -88,3 +98,23 @@ is ($@, '', 'no error'); like ($@, qr/division/, "eval caught division"); is($c, 2, "missing die hook"); } + +# [perl #20444] Constant folding should not change the meaning of match +# operators. +{ + local *_; + $_="foo"; my $jing = 1; + ok scalar $jing =~ (1 ? /foo/ : /bar/), + 'lone m// is not bound via =~ after ? : folding'; + ok scalar $jing =~ (0 || /foo/), + 'lone m// is not bound via =~ after || folding'; + ok scalar $jing =~ (1 ? s/foo/foo/ : /bar/), + 'lone s/// is not bound via =~ after ? : folding'; + ok scalar $jing =~ (0 || s/foo/foo/), + 'lone s/// is not bound via =~ after || folding'; + $jing = 3; + ok scalar $jing =~ (1 ? y/fo// : /bar/), + 'lone y/// is not bound via =~ after ? : folding'; + ok scalar $jing =~ (0 || y/fo//), + 'lone y/// is not bound via =~ after || folding'; +} |