Skip to content

Commit

Permalink
RakuAST: mixin Callable[T] on routines with return type in signature
Browse files Browse the repository at this point in the history
The returns trait already did this, and now the --> T in the signature
follows this example.
  • Loading branch information
niner committed Oct 24, 2022
1 parent 8be4800 commit 119ea0c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Raku/ast/code.rakumod
Expand Up @@ -847,7 +847,7 @@ class RakuAST::PointyBlock is RakuAST::Block {
class RakuAST::Routine is RakuAST::LexicalScope is RakuAST::Term is RakuAST::Code
is RakuAST::Meta is RakuAST::Declaration
is RakuAST::ImplicitDeclarations is RakuAST::AttachTarget
is RakuAST::PlaceholderParameterOwner
is RakuAST::PlaceholderParameterOwner is RakuAST::ImplicitLookups
is RakuAST::BeginTime is RakuAST::TraitTarget {
has RakuAST::Name $.name;
has RakuAST::Signature $.signature;
Expand Down Expand Up @@ -878,12 +878,27 @@ class RakuAST::Routine is RakuAST::LexicalScope is RakuAST::Term is RakuAST::Cod
Nil
}

method PRODUCE-IMPLICIT-LOOKUPS() {
self.IMPL-WRAP-LIST([
RakuAST::Type::Setting.new(RakuAST::Name.from-identifier('Callable'))
])
}

method PRODUCE-META-OBJECT() {
my $routine := nqp::create(self.IMPL-META-OBJECT-TYPE);
my $signature := self.placeholder-signature || self.signature;
nqp::bindattr($routine, Code, '$!signature', $signature.meta-object);
nqp::bindattr($signature.meta-object, Signature, '$!code', $routine);

if $signature.meta-object.has_returns {
my @lookups := self.IMPL-UNWRAP-LIST(self.get-implicit-lookups);
my $Callable := @lookups[0].compile-time-value;
$routine.HOW.mixin(
$routine,
$Callable.HOW.parameterize($Callable, $signature.meta-object.returns)
);
}

if nqp::istype(self.body, RakuAST::OnlyStar) {
$routine.set_onlystar;
}
Expand Down

0 comments on commit 119ea0c

Please sign in to comment.