[perl #123776] Binding a variable at BEGIN time doesn't stick aruond for runtime

[email protected] ("Zoffix Znet via RT")
Newsgroups perl.perl6.compiler
Message-ID <[email protected]>
On Tue, 30 Jan 2018 15:08:38 -0800, [email protected] wrote:
> On Fri, 01 Dec 2017 12:09:05 -0800, [email protected] wrote:
> > Still reproducible (2017.11, HEAD(5929887)), but is supposed to work?
> 
> Don't see any reason why that'd be questionable.
> 
> > On 2015-02-09 17:43:52, [email protected] wrote:
> > > m: my $a; BEGIN { $a := 1; say $a; }; say $a;
> > > rakudo-{parrot,moar} 0cb22e: OUTPUT«1␤(Any)␤»
> > >
> > > m: my $a; BEGIN { $a = 1; say $a; }; say $a; # works with assignment
> > > rakudo-{parrot,moar} 0cb22e: OUTPUT«1␤1␤»
> 
> 
> Another manifestation of the same bug:
> 
> <Zoffix__> m: BEGIN { my $a1 := 42; say $a1; }
> <camelia> rakudo-moar deffe54b8: OUTPUT: «42␤»
> <Zoffix__> m: BEGIN { my $a1 = 42; say $a1; }
> <camelia> rakudo-moar deffe54b8: OUTPUT: «42␤»
> <Zoffix__> m: BEGIN my $a1 = 42; say $a1;
> <camelia> rakudo-moar deffe54b8: OUTPUT: «42␤»
> <Zoffix__> m: BEGIN my $a1 := 42; say $a1;
> <camelia> rakudo-moar deffe54b8: OUTPUT: «(Mu)␤»



Tracked this to Perl6::World.compile_in_context but leaving it there, as it's getting too hard.
Need to gain a few levels first.

The comment in the method reads:
   # Create outer lexical contexts with all symbols visible. Maybe
   # we can be a bit smarter here some day. But for now we just make a
   # single frame and copy all the visible things into it.

So I imagine the binding gets made to this faked out block and never propagates back to the source where all the lexicals were copied from.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.