<commit_before>use v6;
use Test;

plan 18;

# L<S04/The Relationship of Blocks and Declarations/"our $foo" introduces a lexically scoped
# alias for a variable in the current package
our $a = 1;
{ # create a new lexical scope
    is($a, 1, '$a is still the outer $a');
    { # create another new lexical scope
        my $a = 2;
        is($a, 2, '$a is now the lexical (inner) $a');
    }
}
is($a, 1, '$a has not changed');

# should it be allowed to declare our-scoped vars more than once?
{
    our $a = 3;
    is($a, 3, '$a is now another lexical (inner) $a');
}
is($a, 3, '$a has changed'); # XXX is that right?

# eval() introduces new lexical scope
is( eval('
my $e = 11;
{ 
    my $e = 3 #OK not used
};
$e;
'), 11, '$e is available, and the outer value has not changed' );

# test that our (@array, @otherarray) correctly declares
# and initializes both arrays
{
    our (@a, @b);
    lives_ok { @a.push(2) }, 'Can use @a';
    lives_ok { @b.push(3) }, 'Can use @b';
    is ~@a, '2', 'push actually worked on @a';
    is ~@b, '3', 'push actually worked on @b';
}

our $c = 42; #OK not used
{
    my $c = $c;
    nok( $c.defined, 'my $c = $c; can not see the value of the outer $c');
}

# check that our-scoped variables really belong to the package
{
    class D1 {
        our $d1 = 7;
        is($d1, 7, "we can of course see the variable from its own package");
        
        class D2 {
            our $d2 = 8;
            {
                our $d3 = 9;
            }
            {
                is($d3, 9, "variables are seen within other lexical child blocks");
                
                class D3 {
                    is($d3, 9, " ... and from within child classes");
                }
            }
            is($d3, 9, "variables leak from lexical blocks");
        }
        eval_dies_ok('$d2', 'our() variable not yet visible outside its package');
        eval_dies_ok('$d3', 'our() variable not yet visible outside its package');
        
    }
    eval_dies_ok('$d1', 'our() variable not yet visible outside its package');
}

# vim: ft=perl6<commit_msg>use packages when we talk about packages<commit_after>use v6;
use Test;

plan 18;

# L<S04/The Relationship of Blocks and Declarations/"our $foo" introduces a lexically scoped
# alias for a variable in the current package
our $a = 1;
{ # create a new lexical scope
    is($a, 1, '$a is still the outer $a');
    { # create another new lexical scope
        my $a = 2;
        is($a, 2, '$a is now the lexical (inner) $a');
    }
}
is($a, 1, '$a has not changed');

# should it be allowed to declare our-scoped vars more than once?
{
    our $a = 3;
    is($a, 3, '$a is now another lexical (inner) $a');
}
is($a, 3, '$a has changed'); # XXX is that right?

# eval() introduces new lexical scope
is( eval('
my $e = 11;
{ 
    my $e = 3 #OK not used
};
$e;
'), 11, '$e is available, and the outer value has not changed' );

# test that our (@array, @otherarray) correctly declares
# and initializes both arrays
{
    our (@a, @b);
    lives_ok { @a.push(2) }, 'Can use @a';
    lives_ok { @b.push(3) }, 'Can use @b';
    is ~@a, '2', 'push actually worked on @a';
    is ~@b, '3', 'push actually worked on @b';
}

our $c = 42; #OK not used
{
    my $c = $c;
    nok( $c.defined, 'my $c = $c; can not see the value of the outer $c');
}

# check that our-scoped variables really belong to the package
{
    package D1 {
        our $d1 = 7;
        is($d1, 7, "we can of course see the variable from its own package");
        
        package D2 {
            our $d2 = 8;
            {
                our $d3 = 9;
            }
            {
                is($d3, 9, "variables are seen within other lexical child blocks");
                
                package D3 {
                    is($d3, 9, " ... and from within child packages");
                }
            }
            is($d3, 9, "variables leak from lexical blocks");
        }
        eval_dies_ok('$d2', 'our() variable not yet visible outside its package');
        eval_dies_ok('$d3', 'our() variable not yet visible outside its package');
        
    }
    eval_dies_ok('$d1', 'our() variable not yet visible outside its package');
}

# vim: ft=perl6
{'fraction_non_alphanumeric': 0.13716184148077837, 'fraction_numerical': 0.021357380161366873, 'mean_word_length': 2.1384959046909904, 'pattern_counts': {'":': 0, '<': 5, '<?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': '732204', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1386, 'n_words': 559}