Skip to content

Commit 3121b87

Browse files
committed
DB::eval CvOUTSIDE: some more tests
1 parent 562985f commit 3121b87

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

t/op/eval.t

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ BEGIN {
66
set_up_inc('../lib');
77
}
88

9-
plan(tests => 170);
9+
plan(tests => 172);
1010

1111
eval 'pass();';
1212

@@ -392,6 +392,57 @@ our $x = 1;
392392
is($d7->(), 3);
393393
}
394394

395+
{
396+
# github 22547
397+
# these produce the expected results with 5.40.0
398+
local $TODO = "eval from DB outside chain is broken";
399+
fresh_perl_is(<<'CODE', "1.1\n1.2\n2\n", {}, "lexical lookup from DB::");
400+
use builtin qw(ceil);
401+
use strict;
402+
403+
package DB {
404+
sub do_eval { eval shift or $@; }
405+
}
406+
407+
{
408+
my $xx = 1.2;
409+
my sub f {
410+
print DB::do_eval(shift), "\n";
411+
}
412+
f('1.1');
413+
f('$xx');
414+
f('ceil(1.1)');
415+
}
416+
CODE
417+
418+
# subtley different, one of the suggested solutions was to make
419+
# CvOUTSIDE a weak reference, but in the case below $f exits before
420+
# the eval is called, so the outside link from the closure it returns
421+
# would break for a weak reference.
422+
fresh_perl_is(<<'CODE', "1.1\n1.2\n2\n", {}, "lexical lookup from DB::");
423+
use strict;
424+
425+
package DB {
426+
sub do_eval { eval shift or $@; }
427+
}
428+
429+
sub g {
430+
my $yy;
431+
my $f = sub {
432+
$yy; # closure
433+
use builtin qw(ceil);
434+
our $xx = 1.2;
435+
my $yy = shift;
436+
return sub { print DB::do_eval($yy) || $@, "\n" };
437+
};
438+
return $f->(shift);
439+
}
440+
g('1.1')->();
441+
g('$xx')->();
442+
g('ceil(1.1)')->();
443+
CODE
444+
}
445+
395446
# [perl #19022] used to end up with shared hash warnings
396447
# The program should generate no output, so anything we see is on stderr
397448
my $got = runperl (prog => '$h{a}=1; foreach my $k (keys %h) {eval qq{\$k}}',

0 commit comments

Comments
 (0)