Skip to content

Commit

Permalink
Test for concise error on sinking last statement.
Browse files Browse the repository at this point in the history
If the last statement in a file used to need sinking, and doing so
threw an exception, we'd spit out an epic low-level backtrace rather
than a nice high-level one. Fix that by making non-EVAL and non-REPL
stuff we compile put the last statement in sink context in the code we
generate rather than having MAIN do the sinking. Also means a trailing
0; in a file now warns.
  • Loading branch information
jnthn committed Jul 30, 2015
1 parent 0a1da50 commit fac28d3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/Perl6/Actions.nqp
Expand Up @@ -294,6 +294,11 @@ class Perl6::Actions is HLL::Actions does STDActions {
$*POD_PAST,
statementlist_with_handlers($/)
);
unless $*NEED_RESULT {
# Evaluate last statement in sink context, by pushing another
# statement after it, unless we need the result.
$mainline.push(QAST::WVal.new( :value($*W.find_symbol(['Nil'])) ));
}
fatalize($mainline) if %*PRAGMAS<fatal>;

if %*COMPILING<%?OPTIONS><p> { # also covers the -np case, like Perl 5
Expand Down
3 changes: 3 additions & 0 deletions src/Perl6/Grammar.nqp
Expand Up @@ -379,6 +379,9 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
%*HOW<knowhow> := nqp::knowhow();
%*HOW<package> := nqp::knowhow();

# Will we use the result of this? (Yes for EVAL and REPL).
my $*NEED_RESULT := nqp::existskey(%*COMPILING<%?OPTIONS>, 'outer_ctx');

# Symbol table and serialization context builder - keeps track of
# objects that cross the compile-time/run-time boundary that are
# associated with this compilation unit.
Expand Down
7 changes: 2 additions & 5 deletions src/main.nqp
Expand Up @@ -43,15 +43,12 @@ sub MAIN(*@ARGS) {
sub MAIN(@ARGS) {
#?endif
# Enter the compiler.
my $result := $comp.command_line(@ARGS, :encoding('utf8'), :transcode('ascii iso-8859-1'));
if !nqp::isnull($result) && nqp::isconcrete($result) && nqp::can($result, 'sink') {
$result.sink();
}
$comp.command_line(@ARGS, :encoding('utf8'), :transcode('ascii iso-8859-1'));

# Run any END blocks before exiting.
my @END := nqp::gethllsym('perl6', '@END_PHASERS');
while +@END {
$result := (@END.shift)();
my $result := (@END.shift)();
nqp::can($result, 'sink') && $result.sink();
CATCH { $comp.handle-exception($_); }
CONTROL { $comp.handle-control($_); }
Expand Down

0 comments on commit fac28d3

Please sign in to comment.