Skip to content

Commit

Permalink
Awesomify and test unit-scope sub error
Browse files Browse the repository at this point in the history
Fixes #1364
  • Loading branch information
zoffixznet committed Jan 5, 2018
1 parent ffabfdb commit 900c1b5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/Perl6/Grammar.nqp
Expand Up @@ -2803,7 +2803,11 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
|| ';'
{
if $<deflongname> ne 'MAIN' {
$/.typed_panic("X::UnitScope::Invalid", what => "sub", where => "except on a MAIN sub");
$/.typed_panic("X::UnitScope::Invalid", what => "sub",
where => "except on a MAIN sub", suggestion =>
'Please use the block form. If you did not mean to '
~ "declare a unit-scoped sub,\nperhaps you accidentally " ~ "placed a semicolon right after routine's definition?"
);
}
unless $*begin_compunit {
$/.typed_panic("X::UnitScope::TooLate", what => "sub");
Expand Down
4 changes: 2 additions & 2 deletions src/core/Exception.pm
Expand Up @@ -2793,9 +2793,9 @@ my class X::EXPORTHOW::Conflict does X::Comp {
my class X::UnitScope::Invalid does X::Syntax {
has $.what;
has $.where;
has Str:D $.suggestion = 'Please use the block form.';
method message() {
"A unit-scoped $.what definition is not allowed $.where;\n"
~ "Please use the block form."
"A unit-scoped $.what definition is not allowed $.where;\n$!suggestion"
}
}

Expand Down
7 changes: 6 additions & 1 deletion t/05-messages/02-errors.t
Expand Up @@ -2,7 +2,7 @@ use lib <t/packages/>;
use Test;
use Test::Helpers;

plan 30;
plan 31;

# RT #132295

Expand Down Expand Up @@ -256,4 +256,9 @@ subtest 'cannot use Int type object as an operand' => {
'A Rational instance cannot be powered by an Int type object';
}

# https://github.com/rakudo/rakudo/issues/1364
throws-like sub meows;, X::UnitScope::Invalid, :message(/
"placed a semicolon right after routine's definition"
/), 'unit-scoped sub def mentions potential unwanted semicolon';

# vim: ft=perl6 expandtab sw=4

0 comments on commit 900c1b5

Please sign in to comment.