Skip to content

Commit

Permalink
Compile time error for misplaced whenever
Browse files Browse the repository at this point in the history
I thought we already were doing this, but: make it a compile time
error to have a `whenever` block that is not lexically within a
`supply` or `react` block. Hopefully nobody was relying on this not
being an error; if they are, we can ban it in 6.d, and conditionally
do the opts that rely on it only for 6.d also. However, it seems
highly unlikely.
  • Loading branch information
jnthn committed Jan 15, 2018
1 parent d0be53a commit 7672e34
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/Perl6/Grammar.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
:my $*INVOCANT_OK := 0;
:my $*INVOCANT;
:my $*ARG_FLAT_OK := 0;
:my $*WHENEVER_COUNT := -1; # -1 indicates whenever not valid here
# Error related. There are three levels: worry (just a warning), sorry
# (fatal but not immediately so) and panic (immediately deadly). There
Expand Down Expand Up @@ -1551,7 +1552,12 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
}
rule statement_control:sym<whenever> {
<sym><.kok> {}
<sym><.kok>
[
|| <?{ $*WHENEVER_COUNT >= 0 }>#
|| <.typed_panic('X::Comp::WheneverOutOfScope')>
]
{ $*WHENEVER_COUNT++ }
<xblock(1)>
}
Expand Down Expand Up @@ -1802,8 +1808,14 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
token statement_prefix:sym<gather> { <sym><.kok> <blorst> }
token statement_prefix:sym<once> { <sym><.kok> <blorst> }
token statement_prefix:sym<start> { <sym><.kok> <blorst> }
token statement_prefix:sym<supply> { <sym><.kok> <blorst> }
token statement_prefix:sym<react> { <sym><.kok> <blorst> }
token statement_prefix:sym<supply> {
:my $*WHENEVER_COUNT := 0;
<sym><.kok> <blorst>
}
token statement_prefix:sym<react> {
:my $*WHENEVER_COUNT := 0;
<sym><.kok> <blorst>
}
token statement_prefix:sym<do> { <sym><.kok> <blorst> }
token statement_prefix:sym<DOC> {
<sym><.kok> $<phase>=['BEGIN' || 'CHECK' || 'INIT']<.end_keyword><.ws>
Expand Down
8 changes: 7 additions & 1 deletion src/core/Exception.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2881,7 +2881,13 @@ my class X::Seq::NotIndexable is Exception {

my class X::WheneverOutOfScope is Exception {
method message() {
"Cannot have a 'whenever' block outside the scope of a 'supply' block"
"Cannot have a 'whenever' block outside the scope of a 'supply' or 'react' block"
}
}

my class X::Comp::WheneverOutOfScope does X::Comp {
method message() {
"Cannot have a 'whenever' block outside the scope of a 'supply' or 'react' block"
}
}

Expand Down

0 comments on commit 7672e34

Please sign in to comment.