Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Build method signature before parsing body.
This means we also code-gen native lexical readonly parameters better
and get errors at compile time for trying to assign to them.
  • Loading branch information
jnthn committed Feb 24, 2015
1 parent 7b41e74 commit 4dd6ccb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
11 changes: 3 additions & 8 deletions src/Perl6/Actions.nqp
Expand Up @@ -2813,14 +2813,8 @@ class Perl6::Actions is HLL::Actions does STDActions {
}
$past.name($name ?? $name !! '<anon>');

# Do the various tasks to trun the block into a method code object.
my $meta := $<specials> && ~$<specials> eq '^';
my %sig_info := $<multisig> ?? $<multisig>.ast !! hash(parameters => []);
my $invocant_type := $*W.find_symbol([
$<longname> && $*W.is_lexical('$?CLASS') && !$meta ?? '$?CLASS' !! 'Mu']);
my $signature := $*W.create_signature_and_params($/, %sig_info, $past, 'Any',
:method, :$invocant_type);
my $code := methodize_block($/, $*DECLARAND, $past, $signature, %sig_info, :yada(is_yada($/)));
my $code := methodize_block($/, $*DECLARAND, $past, $*SIG_OBJ,
%*SIG_INFO, :yada(is_yada($/)));

# If it's a proto but not an onlystar, need some variables for the
# {*} implementation to use.
Expand Down Expand Up @@ -2863,6 +2857,7 @@ class Perl6::Actions is HLL::Actions does STDActions {

# Install method.
if $name {
my $meta := $<specials> && ~$<specials> eq '^';
install_method($/, $name, $*SCOPE, $code, $outer, :$meta,
:private($<specials> && ~$<specials> eq '!'));
}
Expand Down
24 changes: 23 additions & 1 deletion src/Perl6/Grammar.nqp
Expand Up @@ -2662,6 +2662,8 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
{ $*DECLARATOR_DOCS := '' }
:my $*POD_BLOCK;
:my $*DECLARAND := $*W.stub_code_object($d eq 'submethod' ?? 'Submethod' !! 'Method');
:my $*SIG_OBJ;
:my %*SIG_INFO;
{
if $*PRECEDING_DECL_LINE < $*LINE_NO {
$*PRECEDING_DECL_LINE := $*LINE_NO;
Expand All @@ -2684,7 +2686,27 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
<trait>*
| <?>
]
{ $*IN_DECL := ''; }
{
$*IN_DECL := '';

my $meta := $<specials> && ~$<specials> eq '^';
my $invocant_type := $*W.find_symbol([
$<longname> && $*W.is_lexical('$?CLASS') && !$meta
?? '$?CLASS'
!! 'Mu']);
if $<multisig> {
%*SIG_INFO := $<multisig>.ast;
$*SIG_OBJ := $*W.create_signature_and_params($<multisig>,
%*SIG_INFO, $*W.cur_lexpad(), 'Any', :method,
:$invocant_type);
}
else {
%*SIG_INFO := hash(parameters => []);
$*SIG_OBJ := $*W.create_signature_and_params($/,
%*SIG_INFO, $*W.cur_lexpad(), 'Any', :method,
:$invocant_type);
}
}
[
|| <onlystar>
|| <blockoid>
Expand Down

0 comments on commit 4dd6ccb

Please sign in to comment.