Skip to content
Permalink
Browse files

Improve error message when using placeholders with methods

Addresses GH #2320
  • Loading branch information...
hoelzro committed Oct 23, 2018
1 parent 10693d1 commit deae5bcdb82159e55d65124665c8ce6d31c6e4af
Showing with 20 additions and 1 deletion.
  1. +20 −1 src/Perl6/Actions.nqp
@@ -4269,7 +4269,26 @@ class Perl6::Actions is HLL::Actions does STDActions {
else {
$past := WANTED($<blockoid>.ast,'method_def');
if $past.ann('placeholder_sig') {
$/.PRECURSOR.panic('Placeholder variables cannot be used in a method');
my $placeholders := nqp::iterator($past.ann('placeholder_sig'));
my @non-placeholder-names;
my $method-name := $<longname><name>;
while $placeholders {
my $placeholder := nqp::shift($placeholders);
my $name := $placeholder<placeholder>;
my $non-placeholder-name;
if $placeholder<named_names> {
$non-placeholder-name := nqp::concat(':', nqp::concat(nqp::substr($name, 0, 1), nqp::substr($name, 2)));
} else {
$non-placeholder-name := nqp::concat(nqp::substr($name, 0, 1), nqp::substr($name, 2));
}
nqp::push( @non-placeholder-names, $non-placeholder-name);
}

my $non-placeholder-names := nqp::join(', ', @non-placeholder-names);

my $first-placeholder-name := $past.ann('placeholder_sig')[0]<placeholder>;

$/.PRECURSOR.panic("Placeholder variables (eg. $first-placeholder-name) cannot be used in a method.\nPlease specify an explicit signature, like $*METHODTYPE $method-name ($non-placeholder-names) \{ ... \}");
}
if is_clearly_returnless($past) {
$past[1] := QAST::Op.new(

0 comments on commit deae5bc

Please sign in to comment.
You can’t perform that action at this time.