Skip to content

Commit

Permalink
Fix use of %_ and @_ when they've been declared in a signature (or au…
Browse files Browse the repository at this point in the history
…to-included in the case of methods).
  • Loading branch information
jnthn committed Apr 4, 2010
1 parent f5b18c9 commit c9db3d6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Perl6/Actions.pm
Expand Up @@ -713,10 +713,14 @@ sub make_variable($/, $name) {
$past := add_placeholder_parameter($<sigil>.Str, $<desigilname>.Str, :named($<twigil>[0] eq ':'));
}
elsif ~$/ eq '@_' {
$past := add_placeholder_parameter('@', '_', :slurpy_pos(1));
unless get_nearest_signature().declares_symbol('@_') {
$past := add_placeholder_parameter('@', '_', :slurpy_pos(1));
}
}
elsif ~$/ eq '%_' {
$past := add_placeholder_parameter('%', '_', :slurpy_named(1));
unless get_nearest_signature().declares_symbol('%_') {
$past := add_placeholder_parameter('%', '_', :slurpy_named(1));
}
}
else {
my $attr_alias := is_attr_alias($past.name);
Expand Down Expand Up @@ -1429,6 +1433,7 @@ method signature($/) {
$signature.add_parameter($param);
$cur_param := $cur_param + 1;
}
@BLOCK[0]<signature> := $signature;
make $signature;
}

Expand Down Expand Up @@ -2560,6 +2565,17 @@ sub add_placeholder_parameter($sigil, $ident, :$named, :$slurpy_pos, :$slurpy_na
return PAST::Var.new( :name(~$sigil ~ ~$ident), :scope('lexical') );
}

# Looks through the blocks for the first one with a signature and returns
# that signature.
sub get_nearest_signature() {
for @BLOCK {
if pir::defined__IP($_<signature>) {
return $_<signature>;
}
}
Perl6::Compiler::Signature.new()
}

# Wraps a sub up in a block type.
sub create_code_object($block, $type, $multiness, $lazy_init) {
my @name := Perl6::Grammar::parse_name($type);
Expand Down
11 changes: 11 additions & 0 deletions src/Perl6/Compiler/Signature.pm
Expand Up @@ -365,6 +365,17 @@ method entries() {
$!entries
}
# Tests if the signature declares the given symbol.
method declares_symbol($name) {
for self.entries {
if $_.var_name eq $name {
return 1;
}
}
return 0;
}
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
Expand Down

0 comments on commit c9db3d6

Please sign in to comment.