diff --git a/src/Perl6/World.nqp b/src/Perl6/World.nqp index aca9d4530de..6a2826f89ec 100644 --- a/src/Perl6/World.nqp +++ b/src/Perl6/World.nqp @@ -1433,7 +1433,7 @@ class Perl6::World is HLL::World { # Installs a lexical symbol. Takes a QAST::Block object, name and # the type of container to install. - method install_lexical_container($block, str $name, %cont_info, $descriptor, :$scope, :$package) { + method install_lexical_container($block, str $name, %cont_info, $descriptor, :$scope, :$package, :$cont = self.build_container(%cont_info, $descriptor)) { # Add to block, if needed. Note that it doesn't really have # a compile time value. my $var; @@ -1478,9 +1478,6 @@ class Perl6::World is HLL::World { return nqp::null(); } - # Build container. - my $cont := self.build_container(%cont_info, $descriptor); - self.add_object($cont); $block.symbol($name, :value($cont)); self.install_package_symbol_unchecked($package, $name, $cont) if $scope eq 'our'; @@ -1500,7 +1497,7 @@ class Perl6::World is HLL::World { $cd } - # Builds a container. + # Builds a container and adds it to the SC. method build_container(%cont_info, $descriptor) { my $cont; my $cont_type := %cont_info; @@ -1524,6 +1521,7 @@ class Perl6::World is HLL::World { $cont := $cont_type.new; try nqp::bindattr($cont, %cont_info, '$!descriptor', $descriptor); } + self.add_object($cont); $cont } @@ -1678,13 +1676,13 @@ class Perl6::World is HLL::World { } # Installs one of the magical lexicals ($_, $/ and $!). Uses a cache to - # avoid massive duplication of container descriptors. + # avoid massive duplication of containers and container descriptors. method install_lexical_magical($block, $name) { my %magical_cds := self.context().magical_cds(); if nqp::existskey(%magical_cds, $name) { my $mcd := nqp::atkey(%magical_cds, $name); - self.install_lexical_container($block, $name, $mcd[0], $mcd[1]); + self.install_lexical_container($block, $name, $mcd[0], $mcd[1], :cont($mcd[2])); } else { my $Mu := self.find_symbol(['Mu']); @@ -1702,8 +1700,10 @@ class Perl6::World is HLL::World { my $desc := self.create_container_descriptor($Mu, 1, $name, $WHAT, 1); - %magical_cds{$name} := [%info, $desc]; - self.install_lexical_container($block, $name, %info, $desc); + my $cont := self.build_container(%info, $desc); + + %magical_cds{$name} := [%info, $desc, $cont]; + self.install_lexical_container($block, $name, %info, $desc, :cont($cont)); } }