Skip to content

Commit

Permalink
[JVM] Let CONTROL do it's work in nqp::handle
Browse files Browse the repository at this point in the history
Before, a labeled exception wasn't caught by CONTROL.

Again, I'm not very sure about this patch, but it helps with one
failing test and has no (additional) fallout for spectest.
Please revert if it's the wrong thing to do.

There might be other cases where unwind_check is called without
passing a value for $handler_cares. The check for $handler_cares
was introduced back in 2014 with 1783628.
  • Loading branch information
usev6 committed Apr 28, 2019
1 parent 1b07236 commit f0017e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/vm/jvm/QAST/Compiler.nqp
Expand Up @@ -1640,10 +1640,10 @@ QAST::OperationsJAST.add_core_op('handle', :!inlinable, sub ($qastcomp, $op) {
QAST::Op.new( :op('exception') )
)));
my $push_target := $hblock;
my $has_label := 0;
my $handler_cares := 0;
for @children -> $type, $handler {
$handler_cares := 1 if $type eq 'CONTROL' || $type eq 'LABELED';
if $type eq 'LABELED' {
$has_label := 1;
# Rethrow if a label was requested which we are not in charge for.
$hblock.push(
QAST::Op.new(
Expand Down Expand Up @@ -1741,7 +1741,7 @@ QAST::OperationsJAST.add_core_op('handle', :!inlinable, sub ($qastcomp, $op) {
# after unwind" flag, used to force this whole block to exit.
my $catchil := JAST::InstructionList.new();
my $exitlbl := JAST::Label.new( :name($qastcomp.unique('unwindexit')) );
$qastcomp.unwind_check($catchil, $handler, :outer($*HANDLER_IDX), :handler_cares($has_label));
$qastcomp.unwind_check($catchil, $handler, :outer($*HANDLER_IDX), :$handler_cares);
$catchil.append(JAST::Instruction.new( :op('getfield'), $TYPE_EX_UNWIND, 'result', $TYPE_SMO ));
$catchil.append(JAST::Instruction.new( :op('astore'), $result ));
$catchil.append(JAST::Instruction.new( :op('aload'), 'cf' ));
Expand Down
14 changes: 5 additions & 9 deletions t/nqp/044-try-catch.t
Expand Up @@ -515,15 +515,11 @@ is(catch_unlabeled({
});
}), 'control', 'an unlabeled exception is caught by CONTROL');

if nqp::getcomp('nqp').backend.name eq 'jvm' {
skip('catching a labeled exception with CONTROL seems to have a bug on the jvm');
} else {
is(catch_labeled({
catch_with_control({
THROW(nqp::add_i(nqp::const::CONTROL_TAKE, nqp::const::CONTROL_LABELED), Label2)
});
}), 'control', 'a labeled exception is caught by CONTROL');
}
is(catch_labeled({
catch_with_control({
THROW(nqp::add_i(nqp::const::CONTROL_TAKE, nqp::const::CONTROL_LABELED), Label2)
});
}), 'control', 'a labeled exception is caught by CONTROL');

{
my $ex;
Expand Down

0 comments on commit f0017e9

Please sign in to comment.