Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add errors for bougs $!x and $.x parameter use.
Catch $.x usage in a submethod, plus catch sub ($!x) { } even when
the sub is inside of a class. This took a bit more doing than first
expected, since 'has ($.x, $.y)' is also parsed using a signature.
  • Loading branch information
jnthn committed Jul 15, 2015
1 parent 270d179 commit 63ebb34
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/Perl6/Actions.nqp
Expand Up @@ -4011,7 +4011,10 @@ Compilation unit '$file' contained the following violations:
}
}
elsif $twigil eq '!' {
%*PARAM_INFO<bind_attr> := 1;
if !$*HAS_SELF && $*SURROUNDING_DECL ne 'variable' {
$*W.throw($/, ['X', 'Syntax', 'NoSelf'], variable => ~$/);
}
%*PARAM_INFO<bind_attr> := 1;
my int $succ := 1;
try {
%*PARAM_INFO<attr_package> := $*W.find_symbol(['$?CLASS']);
Expand All @@ -4024,6 +4027,14 @@ Compilation unit '$file' contained the following violations:
}
}
elsif $twigil eq '.' {
if $*SURROUNDING_DECL ne 'variable' {
if !$*HAS_SELF {
$*W.throw($/, ['X', 'Syntax', 'NoSelf'], variable => ~$/);
}
elsif $*HAS_SELF eq 'partial' {
$*W.throw($/, ['X', 'Syntax', 'VirtualCall'], call => ~$/);
}
}
%*PARAM_INFO<bind_accessor> := 1;
if $<name> {
%*PARAM_INFO<variable_name> := ~$<name>;
Expand Down
6 changes: 3 additions & 3 deletions src/Perl6/Grammar.nqp
Expand Up @@ -2237,7 +2237,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
|| <?{ $*SCOPE eq 'has' }> <.newpad> [ <.ws> <initializer> ]? { $*ATTR_INIT_BLOCK := $*W.pop_lexpad() }
|| [ <.ws> <initializer> ]?
]
| '(' ~ ')' <signature> [ <.ws> <trait>+ ]? [ <.ws> <initializer> ]?
| '(' ~ ')' <signature('variable')> [ <.ws> <trait>+ ]? [ <.ws> <initializer> ]?
| <routine_declarator>
| <regex_declarator>
| <type_declarator>
Expand Down Expand Up @@ -2615,8 +2615,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
<signature>
}

token signature {
:my $*IN_DECL := 'sig';
token signature($*IN_DECL = 'sig') {
:my $*zone := 'posreq';
:my $*multi_invocant := 1;
:my @*seps := nqp::list();
Expand Down Expand Up @@ -2713,6 +2712,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
:dba('formal parameter')
:my $*DOC := $*DECLARATOR_DOCS; # these get cleared later
:my $*POD_BLOCK;
:my $*SURROUNDING_DECL := nqp::getlexdyn('$*IN_DECL');
<.attach_leading_docs>
{
my $line_no := HLL::Compiler.lineof(self.orig(), self.from(), :cache(1));
Expand Down

0 comments on commit 63ebb34

Please sign in to comment.