From 42c2f5a75b079973c8ada06290b9f684fd93ba48 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Wed, 13 Sep 2023 13:12:44 +0200 Subject: [PATCH] RakuAST: reorganize variable stub logic a bit MasterDuke++ for the nudge --- src/Raku/Actions.nqp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Raku/Actions.nqp b/src/Raku/Actions.nqp index 77d94901e5d..504cf43eeda 100644 --- a/src/Raku/Actions.nqp +++ b/src/Raku/Actions.nqp @@ -1896,7 +1896,8 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions { my $/ := $*VARIABLE-MATCH; my str $scope := $*SCOPE; - my $type := $*OFTYPE ?? $*OFTYPE.ast !! Nodify('Type'); + my $type := $*OFTYPE ?? $*OFTYPE.ast !! Nodify('Type'); + my str $sigil := $; my $decl; if $ { @@ -1904,35 +1905,34 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions { my $ast := $desigilname ?? $desigilname.ast !! Nodify('Name').from-identifier(~$desigilname); - my str $sigil := $; + $ast.IMPL-CHECK($*R, $*CU.context, 1); + my str $twigil := $ || ''; + my str $name := $sigil ~ $twigil ~ $ast.canonicalize; my $shape := $ ?? $[0].ast !! Nodify('SemiList'); - $ast.IMPL-CHECK($*R, $*CU.context, 1); my $dynprag := $*LANG.pragma('dynamic-scope'); - my $forced-dynamic := $dynprag - ?? $dynprag($sigil ~ $twigil ~ $ast.canonicalize) - !! 0; + my $forced-dynamic := $dynprag ?? $dynprag($name) !! 0; $decl := Nodify('VarDeclaration', 'Simple').new: - :$scope, :$type, :desigilname($ast), :$sigil, :$twigil, + :$scope, :$type, :$sigil, :$twigil, :desigilname($ast), :$shape, :$forced-dynamic; - if $scope eq 'my' || $scope eq 'state' || $scope eq 'our' { - my str $name := $ ~ ($ || '') ~ $ast; - $/.typed-worry('X::Redeclaration', :symbol($name)) - if $*R.declare-lexical($decl); - } + + $/.typed-worry('X::Redeclaration', :symbol($name)) + if ($scope eq 'my' || $scope eq 'state' || $scope eq 'our') + && $*R.declare-lexical($decl); + self.set-declarand($/, $decl); } else { $scope ne 'my' && $scope ne 'state' ?? $/.panic( - "Cannot declare an anonymous {$scope}-scoped variable" + "Cannot declare an anonymous '$scope' scoped variable" ) !! $ ?? $/.panic( "Cannot declare an anonymous variable with a twigil" ) !! ($decl := Nodify('VarDeclaration', 'Anonymous').new( - :$scope, :$type, :sigil(~$) + :$scope, :$type, :$sigil )); }