<commit_before>use v6;

use Test;

plan 1;

role B { method x { 3; } }

class T does B { }

class S does B
{
        has $.t is rw;
        method x
        {
                $.t.x;
        }
        submethod BUILD(*@_)
        { $!t = T.new }
}

# uncomment below after the bug is fixed. As below line will cause infinite loop;
is S.new.x, 3, "Test class inhrited from the same role caused infinite loop bug";

# vim: ft=perl6<commit_msg>Add tests for private role attribute visibility<commit_after>use v6;

use Test;

plan 7;

{
    role B { method x { 3; } }

    class T does B { }

    class S does B {
        has $.t is rw;
        method x { $.t.x }
        submethod BUILD(*@_) { $!t = T.new }
    }

    is S.new.x, 3, "Test class inherited from the same role caused infinite loop bug";
}

{
    role A {
        has Int $!a;
    }
    class Foo does A {
        method foo { $!a++ }
    }
    my $foo = Foo.new;
    is $foo.foo, 0, 'did we see the Int private attribute from the role';
    is $foo.foo, 1, 'did we update the Int private attribute from the role';
}

#?rakudo skip 'alas, no visibility of native private attributes yet'
{
    role C {
        has int $!c;
    }
    class Bar does A {
        method bar { $!c++ }
    }
    my $bar = Bar.new;
    is $bar.bar, 0, 'did we see the int private attribute from the role';
    is $bar.bar, 1, 'did we update the int private attribute from the role';
}

{
    role AA {
        has Int $!aa;
    }
    role BB does AA {}
    class Baz does BB {
        method baz { $!aa++ }
    }
    my $baz = Baz.new;
    is $baz.baz, 0, 'did we see the Int private attribute from the embedded role';
    is $baz.baz, 1, 'did we update the Int private attribute from the embedded role';
}

# vim: ft=perl6
{'fraction_non_alphanumeric': 0.11243611584327087, 'fraction_numerical': 0.009085746734809767, 'mean_word_length': 1.9763513513513513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5889765', 'n_tokens_mistral': 630, 'n_tokens_neox': 602, 'n_words': 250}