Skip to content

Commit

Permalink
RakuAST: fix role groups not knowing their full name
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Apr 5, 2023
1 parent f380b87 commit 458c0fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
17 changes: 10 additions & 7 deletions src/Raku/ast/package.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,16 @@ class RakuAST::Package
if $name && !$name.is-empty {
my $type-object := self.stubbed-meta-object;
my $current-package := $resolver.current-package;
$type-object.HOW.set_name(
$type-object,
$name.qualified-with(
my $full-name := $current-package =:= $resolver.get-global
?? $name
!! $name.qualified-with(
RakuAST::Name.from-identifier-parts(
|nqp::split('::', $current-package.HOW.name($current-package))
)
).canonicalize(:colonpairs(0))
);
$type-object.HOW.set_name(
$type-object,
$full-name.canonicalize(:colonpairs(0))
) if !nqp::eqaddr($current-package, $resolver.get-global);
# Update the Stash's name, too.
nqp::bindattr_s($type-object.WHO, Stash, '$!longname', $type-object.HOW.name($type-object));
Expand All @@ -192,7 +195,7 @@ class RakuAST::Package

elsif $!declarator eq 'role' {
# Find an appropriate existing role group
my $group-name := $name.canonicalize(:colonpairs(0));
my $group-name := $full-name.canonicalize(:colonpairs(0));
my $group := $resolver.resolve-lexical-constant($group-name);
if $group {
$group := $group.compile-time-value;
Expand All @@ -206,12 +209,12 @@ class RakuAST::Package
my $outer := $resolver.find-attach-target('block') // $resolver.find-attach-target('compunit');
$outer.add-generated-lexical-declaration(
RakuAST::VarDeclaration::Implicit::Constant.new(
:name($group-name),
:name($name.canonicalize(:colonpairs(0))),
:value($group)
)
);
if $scope eq 'our' {
self.IMPL-INSTALL-PACKAGE($resolver, $scope, $name, $group, $resolver.current-package);
self.IMPL-INSTALL-PACKAGE($resolver, $scope, $name, $group, $resolver.current-package, :no-lexical);
}
}
# Add ourselves to the role group
Expand Down
15 changes: 9 additions & 6 deletions src/Raku/ast/scoping.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -708,19 +708,22 @@ class RakuAST::PackageInstaller {
str $scope,
RakuAST::Name $name,
Mu $type-object,
RakuAST::Package $current-package
RakuAST::Package $current-package,
Bool :$no-lexical
) {
my $target;
my $final;
my $lexical;
my $pure-package-installation := nqp::istype(self, RakuAST::Package);
if $name.is-identifier {
$final := $name.canonicalize;
$lexical := $resolver.resolve-lexical-constant($final);
if $pure-package-installation || !$lexical {
$resolver.current-scope.merge-generated-lexical-declaration:
:$resolver,
self.IMPL-GENERATE-LEXICAL-DECLARATION($final, $type-object);
unless $no-lexical {
$lexical := $resolver.resolve-lexical-constant($final);
if $pure-package-installation || !$lexical {
$resolver.current-scope.merge-generated-lexical-declaration:
:$resolver,
self.IMPL-GENERATE-LEXICAL-DECLARATION($final, $type-object);
}
}
# If `our`-scoped, also put it into the current package.
if $scope eq 'our' {
Expand Down

0 comments on commit 458c0fc

Please sign in to comment.