Permalink
Browse files

install our-scoped variables in the nextmost package

  • Loading branch information...
1 parent 2441b01 commit ffe441fa9cccb550f21f65a0b5ecd602f226b166 @FROGGS FROGGS committed Apr 1, 2013
Showing with 13 additions and 6 deletions.
  1. +12 −6 src/Perl6/Actions.pm
  2. +1 −0 t/spectest.data
View
@@ -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());
@@ -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 {
View
@@ -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

0 comments on commit ffe441f

Please sign in to comment.