Skip to content
Permalink
Browse files

Do a lot less work upon a redeclaration

The variable is already there, so we don't need to go and do all of
the things we would were it not. This also avoids scribbling over the
things the optimizer uses to tell the difference between a parameter
or declared variable, fixing an issue introduced by the lexical to
local lowering.
  • Loading branch information...
jnthn committed Nov 1, 2018
1 parent 5bbaabb commit 42024539877fbebfdfbbc9b006106454cdaf5187
Showing with 11 additions and 6 deletions.
  1. +11 −6 src/Perl6/Actions.nqp
@@ -3554,7 +3554,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
}

method variable_declarator($/) {
my $past := $<variable>.ast;
my $qast := $<variable>.ast;
my $sigil := $<variable><sigil>;
my $twigil := $<variable><twigil>;
my $desigilname := ~$<variable><desigilname>;
@@ -3566,14 +3566,15 @@ class Perl6::Actions is HLL::Actions does STDActions {
$desigilname := nqp::substr($name, nqp::chars($sigil ~ $twigil));
}

my @post;
for $<post_constraint> {
@post.push($_.ast);
}
if $<variable><desigilname> {
my $lex := $*W.cur_lexpad();
if $lex.symbol($name) {
$/.typed_worry('X::Redeclaration', symbol => $name);
unless $name eq '$_' {
$qast.scope('lexical') if nqp::istype($qast, QAST::Var) && !$qast.scope;
make $qast;
return;
}
}
else {
ensure_unused_in_scope($/, $name, $twigil);
@@ -3582,7 +3583,11 @@ class Perl6::Actions is HLL::Actions does STDActions {
if nqp::elems($<semilist>) > 1 {
$/.panic('Multiple shapes not yet understood');
}
make declare_variable($/, $past, ~$sigil, ~$twigil, $desigilname, $<trait>, $<semilist>, :@post);
my @post;
for $<post_constraint> {
@post.push($_.ast);
}
make declare_variable($/, $qast, ~$sigil, ~$twigil, $desigilname, $<trait>, $<semilist>, :@post);
}

sub ensure_unused_in_scope($/, $name, $twigil) {

0 comments on commit 4202453

Please sign in to comment.
You can’t perform that action at this time.