Last active
February 9, 2023 10:52
-
-
Save lizmat/a61f90d5699b5dfc72c36e692f1390c3 to your computer and use it in GitHub Desktop.
no strict
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Raku/Grammar.nqp b/src/Raku/Grammar.nqp | |
index 87cc1ee7a..487e33163 100644 | |
--- a/src/Raku/Grammar.nqp | |
+++ b/src/Raku/Grammar.nqp | |
@@ -446,15 +446,17 @@ role Raku::Common { | |
if $ast ~~ self.actions.r('Var', 'Lexical') { | |
$ast.resolve-with($*R); | |
unless $ast.is-resolved || $ast.sigil eq '&' { | |
- my str $name := $var.ast.name; | |
- $*LANG.pragma("strict") | |
- ?? self.typed_panic('X::Undeclared', | |
- symbol => $name, is-compile-time => 1 | |
- ) | |
- !! RakuAST::VarDeclaration::Simple.new( | |
- scope => 'our', name => $name | |
- ).resolve-with($*R) | |
- | |
+ self.typed_panic('X::Undeclared', | |
+ symbol => $ast.name, is-compile-time => 1 | |
+ ) if $*LANG.pragma("strict"); | |
+ | |
+ my $declaration := self.actions.r( | |
+ 'VarDeclaration','Simple' | |
+ ).new(scope => 'our', name => $ast.name); | |
+ $*R.declare-lexical($declaration); | |
+ $declaration.attach($*R); | |
+ $ast.set-declaration($declaration); | |
+ $ast.resolve-with($*R); | |
} | |
} | |
} | |
diff --git a/src/Raku/ast/variable-access.rakumod b/src/Raku/ast/variable-access.rakumod | |
index a8e85b84e..e1d6fa027 100644 | |
--- a/src/Raku/ast/variable-access.rakumod | |
+++ b/src/Raku/ast/variable-access.rakumod | |
@@ -11,6 +11,7 @@ class RakuAST::Var::Lexical | |
is RakuAST::Lookup | |
{ | |
has str $.name; | |
+ has RakuAST::Declaration $!declaration; | |
method new(str $name) { | |
my $obj := nqp::create(self); | |
@@ -32,11 +33,23 @@ class RakuAST::Var::Lexical | |
Nil | |
} | |
+ method set-declaration(RakuAST::Declaration $declaration) { | |
+ nqp::bindattr(self, RakuAST::Var::Lexical, '$!declaration', $declaration); | |
+ } | |
+ | |
method IMPL-EXPR-QAST(RakuAST::IMPL::QASTContext $context) { | |
+ if $!declaration { | |
+ $!declaration.IMPL-QAST-DECL($context); | |
+ nqp::bindattr(self, RakuAST::Var::Lexical, '$!declaration', RakuAST::Declaration); | |
+ } | |
self.resolution.IMPL-LOOKUP-QAST($context) | |
} | |
method IMPL-BIND-QAST(RakuAST::IMPL::QASTContext $context, QAST::Node $source-qast) { | |
+ if $!declaration { | |
+ $!declaration.IMPL-QAST-DECL($context); | |
+ nqp::bindattr(self, RakuAST::Var::Lexical, '$!declaration', RakuAST::Declaration); | |
+ } | |
self.resolution.IMPL-BIND-QAST($context, $source-qast) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment