Skip to content

Commit

Permalink
RakuAST: propagate native types to parameter targets
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Oct 24, 2022
1 parent b890099 commit ea1919e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/Raku/ast/signature.rakumod
Expand Up @@ -242,6 +242,7 @@ class RakuAST::Parameter is RakuAST::Meta is RakuAST::Attaching
RakuAST::Signature :$sub-signature, List :$type-captures) {
my $obj := nqp::create(self);
nqp::bindattr($obj, RakuAST::Parameter, '$!type', $type // RakuAST::Type);
$target.set-type($type) if $target && nqp::can($target, 'set-type') && $type;
nqp::bindattr($obj, RakuAST::Parameter, '$!target', $target // RakuAST::ParameterTarget);
nqp::bindattr($obj, RakuAST::Parameter, '$!names', self.IMPL-NAMES($names));
nqp::bindattr($obj, RakuAST::Parameter, '$!invocant', $invocant ?? True !! False);
Expand All @@ -264,6 +265,7 @@ class RakuAST::Parameter is RakuAST::Meta is RakuAST::Attaching

method set-type(RakuAST::Type $type) {
nqp::bindattr(self, RakuAST::Parameter, '$!type', $type);
$!target.set-type($type) if $!target && nqp::can($!target, 'set-type');
Nil
}

Expand Down Expand Up @@ -833,12 +835,24 @@ class RakuAST::ParameterTarget::Var is RakuAST::ParameterTarget is RakuAST::Decl
''
}

method set-type(RakuAST::Type $type) {
nqp::bindattr(self, RakuAST::ParameterTarget::Var, '$!type', $type);
Nil
}

method set-container-type(Mu $type, Mu $of) {
nqp::bindattr(self, RakuAST::ParameterTarget::Var, '$!type', $type);
nqp::bindattr(self, RakuAST::ParameterTarget::Var, '$!of', $of);
}

method PRODUCE-META-OBJECT() {
nqp::bindattr(
self,
RakuAST::ParameterTarget::Var,
'$!of',
$!type.resolution.compile-time-value
) if $!type && nqp::eqaddr($!of, Mu);

my $cont-desc := self.IMPL-CONTAINER-DESCRIPTOR($!of);
self.IMPL-CONTAINER($!of, $cont-desc)
}
Expand All @@ -847,7 +861,13 @@ class RakuAST::ParameterTarget::Var is RakuAST::ParameterTarget is RakuAST::Decl
if $!type {
my $container := self.meta-object;
$context.ensure-sc($container);
QAST::Var.new( :decl('contvar'), :scope('lexical'), :name($!name), :value($container) )
QAST::Var.new(
:decl(nqp::objprimspec($!of) ?? 'var' !! 'contvar'),
:scope('lexical'),
:name($!name),
:value($container),
:returns($!of)
)
}
else {
QAST::Var.new( :decl('var'), :scope('lexical'), :name($!name) )
Expand Down
6 changes: 5 additions & 1 deletion src/Raku/ast/variable-declaration.rakumod
Expand Up @@ -663,7 +663,11 @@ class RakuAST::VarDeclaration::Signature is RakuAST::Declaration is RakuAST::Imp

my @lookups := self.IMPL-UNWRAP-LIST(self.get-implicit-lookups());
my $of := $!type ?? @lookups[0].resolution.compile-time-value !! Mu;
my $type := $!type // RakuAST::Type::Setting.new('Mu');
my $type := $!type;
unless $type {
$type := RakuAST::Type::Setting.new('Mu');
$type.set-resolution($resolver.resolve-lexical-constant-in-setting('Mu'));
}

for @params {
$_.target.set-container-type($type, $of);
Expand Down

0 comments on commit ea1919e

Please sign in to comment.