Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
install our-scoped variables in the nextmost package
  • Loading branch information
FROGGS committed Apr 1, 2013
1 parent 2441b01 commit ffe441f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Perl6/Actions.pm
Expand Up @@ -1863,7 +1863,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
}
}
}
elsif $*SCOPE eq 'our' {
elsif $*SCOPE eq 'our' {
# Twigil handling.
if $twigil eq '.' {
add_lexical_accessor($/, $past, $desigilname, $*W.cur_lexpad());
Expand Down Expand Up @@ -1891,14 +1891,20 @@ class Perl6::Actions is HLL::Actions does STDActions {
$/.CURSOR.panic("Cannot have an anonymous 'our'-scoped variable");
}

my $lex := QAST::Var.new( :name($name), :scope('lexical') );
unless $BLOCK.symbol($name) {
$lex.decl('var');
$BLOCK.symbol($name, :scope('lexical'));
# Search for the nearest package.
my $pkg := $BLOCK;
while !$pkg.symbol('$?PACKAGE') && $pkg<outer>.defined {
$pkg := $pkg<outer>;
}

# Declare that variable within that package.
unless $pkg.symbol($name) {
$pkg.symbol($name, :scope('lexical'));
$pkg[0].push( QAST::Var.new( :name($name), :scope('lexical'), :decl('var') ) );
}
$BLOCK[0].push(QAST::Op.new(
:op('bind'),
$lex,
QAST::Var.new( :name($name), :scope('lexical') ),
$*W.symbol_lookup([$name], $/, :package_only(1), :lvalue(1))));
}
else {
Expand Down
1 change: 1 addition & 0 deletions t/spectest.data
Expand Up @@ -221,6 +221,7 @@ S04-declarations/constant.t
S04-declarations/implicit-parameter.t
S04-declarations/multiple.t
S04-declarations/my.t
S04-declarations/our.t
S04-declarations/state.t
S04-exception-handlers/catch.t
S04-exceptions/fail.t
Expand Down

0 comments on commit ffe441f

Please sign in to comment.