Skip to content

Commit

Permalink
Test post-inc/dec op optimization does not affect custom ops
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Feb 6, 2018
1 parent b545dab commit 9bcee77
Showing 1 changed file with 55 additions and 8 deletions.
63 changes: 55 additions & 8 deletions S06-operator-overloading/prefix.t
Expand Up @@ -78,12 +78,59 @@ subtest 'coverage for crashes in certain operator setups' => {
# }, -6, '(2)';
}

# GH #1315
{
class A {}
my $x;
sub prefix:<++>(A) { $x = 'foo' }
sub postfix:<++>(A) { $x = 'bar' }
A++;
is $x, 'bar', 'static optimization (if exists) is not too early';
# https://github.com/rakudo/rakudo/issues/1315
# https://github.com/rakudo/rakudo/issues/1477
subtest 'postfix-to-prefix-inc-dec opt does not rewrite custom ops' => {
plan 5;
subtest 'custom classes' => {
plan 2;
my class A {}
sub prefix:<++>(A) { flunk 'postfix increment' }
sub postfix:<++>(A) { pass 'postfix increment' }
sub prefix:<-->(A) { flunk 'postfix decrement' }
sub postfix:<-->(A) { pass 'postfix decrement' }
my $var = A.new;
$var++;
$var--;
}
subtest 'core types (Int)' => {
plan 2;
sub prefix:<++>(Int) { flunk 'postfix increment' }
sub postfix:<++>(Int) { pass 'postfix increment' }
sub prefix:<-->(Int) { flunk 'postfix decrement' }
sub postfix:<-->(Int) { pass 'postfix decrement' }
my $var = 42;
$var++;
$var--;
}
subtest 'core types (Num)' => {
plan 2;
sub prefix:<++>(Num) { flunk 'postfix increment' }
sub postfix:<++>(Num) { pass 'postfix increment' }
sub prefix:<-->(Num) { flunk 'postfix decrement' }
sub postfix:<-->(Num) { pass 'postfix decrement' }
my $var = 42e0;
$var++;
$var--;
}
subtest 'core types (native int)' => {
plan 2;
sub prefix:<++>(int) { flunk 'postfix increment' }
sub postfix:<++>(int) { pass 'postfix increment' }
sub prefix:<-->(int) { flunk 'postfix decrement' }
sub postfix:<-->(int) { pass 'postfix decrement' }
my int $var = 42;
$var++;
$var--;
}
subtest 'core types (native num)' => {
plan 2;
sub prefix:<++>(num) { flunk 'postfix increment' }
sub postfix:<++>(num) { pass 'postfix increment' }
sub prefix:<-->(num) { flunk 'postfix decrement' }
sub postfix:<-->(num) { pass 'postfix decrement' }
my num $var = 42e0;
$var++;
$var--;
}
}

0 comments on commit 9bcee77

Please sign in to comment.