Skip to content

Commit

Permalink
Add a test to cover failure + callsame issue.
Browse files Browse the repository at this point in the history
See comment in the test for details.
  • Loading branch information
jnthn committed Jan 3, 2017
1 parent d667dda commit cd43168
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions integration/failure-and-callsame.t
@@ -0,0 +1,35 @@
use Test;

# This test covers a nasty once-bug involving callsame and Failure, where the
# finalization of Failure could steal the target of a callsame and so lead to
# delegation not taking place. Golfed from a bug report on OO::Monitors, which
# turned out to be a bug in Rakudo. This at the time of adding it would fail
# even without any GC stress applied provided a decent number of iterations
# are done (thus the 50 repetitions; it relies on unfortunate timing).

plan 50;

class Grid {
has @.grid;

method change-cell($x, $s) {
@!grid[$x] = $s;
}
}

my $leaving = 0;
Grid.^lookup('change-cell').wrap(-> \SELF, | {
LEAVE ++$leaving;
callsame
});

my $grid = Grid.new();
for ^50 {
$grid.grid = 'BUG' xx 100;
for ^(100 div 2) -> $x {
Failure.new() // ''; # Triggered glitches
$grid.change-cell($x * 2, 'a');
$grid.change-cell($x * 2 + 1, 'b');
}
ok $grid.grid.join !~~ /BUG/, 'callsame + Failure glitch not observed';
}

0 comments on commit cd43168

Please sign in to comment.