I’d say it is a bug you do not get the error with “my ($foo) = 6”, as clearly the first “say $foo” inside the scope is referring to the inner $foo, not the outer $foo. So I’d suggest filing an issue for that: https://github.com/rakudo/rakudo/issues
> On 27 Dec 2018, at 09:29, Raymond Dresens <raymond.dres...@gmail.com> wrote: > > Hello, > > I'm getting up to speed with Perl 6 again after a long while, and I more > or less 'hit my nose' against something that I can reduce to the > following very basic snippet of code > > my $foo = 3; > say $foo; > > { > say $foo; > > my $foo = 6; > > say $foo; > } > > This will not compile with Perl 6 (Rakudo 2018.12) -- lexical symbol > '$foo' is already bound to an outer symbol; the implicit outer binding > must be rewritten as OUTER::<$foo> before you can unambiguously declare > a new '$foo' in this scope. > > This will compile with Perl 5 when I add 'use v5.14;' at the top and it > will then print 3, then 3 then 6 (as expected). > > Well, it seems that I can 'cheat' by simply doing a list assignment: > > my $foo = 3; > say $foo; > > { > say $foo; > > my ($foo) = 6; # avoid `... '$foo' is already bound ...' > > say $foo; > say $foo.WHAT; # is it really an integer? > } > > The output is: > > 3 > (Any) > 6 > (Int) > > This behavior is fine I think (but a little unexpected due to my > experience with Perl 5). > > Is this behavior normal/wanted/intented (from a language/compiler > perspective?). > > Perhaps this shouldn't be and the compiler should also complain in this > list assignment case, or perhaps generate a warning? > > I'm not that confident to state that this is a bug ;) > > Hence the reason why I kind-of report this, > > I hope this is somewhat useful, > > Thanks for your time, > > Regards, > > Raymond Dresens.