Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
nqp-rx fix for contextuals

In NQP, all variables get declared at the beginning of the block. This makes the following code fail:

my $old  := $*VAR;
my $*VAR := $new;

Instead of the old (outer) value of the contextual $*VAR, $old contains Undef. The following one line fix to nqp-rx seems to solve this problem by making NQP declare variables at the same point in the generated PIR as they are in the NQP code.

diff --git i/src/NQP/ w/src/NQP/
index d7c7602..2aba92a 100644
--- i/src/NQP/
+++ w/src/NQP/
@@ -438,7 +438,7 @@ method variable_declarator($/) {
:lvalue(1), :viviself( vivitype($sigil) ),
:node($/) );
$BLOCK.symbol($name, :scope($scope) );
- $BLOCK[0].push($decl);
+ $BLOCK.push($decl);
make $past;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment