Skip to content

Commit

Permalink
RakuAST: fix RakuAST::Package.raku
Browse files Browse the repository at this point in the history
And make the signature argument on replace-body optional to preserve
compatibility.
  • Loading branch information
lizmat committed Mar 13, 2023
1 parent 1d7bf1c commit 23a7c14
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Raku/ast/package.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class RakuAST::Package
$obj
}

method replace-body(RakuAST::Code $body, RakuAST::Signature $signature) {
method replace-body(RakuAST::Code $body, RakuAST::Signature $signature?) {
$body := RakuAST::Block.new unless $body;

# The body of a role is internally a Sub that has the parameterization
Expand Down
19 changes: 11 additions & 8 deletions src/core.c/RakuAST/Raku.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,17 @@ augment class RakuAST::Node {
my $self := self;
if self.declarator eq 'role' {
$self := nqp::clone(self);
$self.replace-body(
RakuAST::Block.new(
body => RakuAST::Blockoid.new(
RakuAST::StatementList.new( # lose fabricated return value
|self.body.body.statement-list.statements.head(*-1)
)
)
)
my $statements := self.body.body.statement-list.statements;
nqp::bindattr($self, RakuAST::Package, '$!body',
$statements.elems == 1
?? RakuAST::Block
!! RakuAST::Block.new(
body => RakuAST::Blockoid.new(
RakuAST::StatementList.new(
|$statements.head(*-1) # lose fabricated return value
)
)
)
);
}

Expand Down

0 comments on commit 23a7c14

Please sign in to comment.