nothingmuch/Sub-Call-Recur

Infinite loop

Opened this issue · 1 comments

    use strict;
    use warnings;
    use Sub::Call::Recur;
    use Test::More;

    sub dec{ $_[0] - 1 };
    my %test = (
        plain => sub {
            my($v,$i,$c) = @_;
            return 0 if $v == 0; # succeed
            return 1 if $c > $i; # fail

            $v = dec( $v );
            recur( $v, $i, $c+1 );
        },
        'copy before recur' => sub {
            my($v,$i,$c) = @_;
            return 0 if $v == 0;
            return 1 if $c > $i;

            $v = 0+dec( $v );
            recur( $v, $i, $c+1 );
        },
        'copy in recur', sub {
            my($v,$i,$c) = @_;
            return 0 if $v == 0;
            return 1 if $c > $i;

            $v = dec( $v );
            recur( 0+$v, $i, $c+1 ); # this is the only one that works
        },
    );

    plan tests => scalar keys %test;

    TEST: while( my( $name, $code ) = each %test ){
        for my $v ( 0..5 ){
            # ( value, initial, count )
            if( $code->($v,$v,0) ){
                fail "$name ($v)";
                next TEST;
            }
        }
        pass $name;
    }

output:

1..3
not ok 1 - plain (2)
#   Failed test 'plain (2)'
#   at test.pl line 40.
ok 2 - copy in recur
not ok 3 - copy before recur (2)
#   Failed test 'copy before recur (2)'
#   at test.pl line 40.
# Looks like you failed 2 tests of 3.

hi, is this still an issue? If so, please create a ticket at rt.cpan.org so all the maintainers can be made aware of it. No one saw this issue filed here.