diff --git a/src/Perl6/World.pm b/src/Perl6/World.pm index d39146f585f..c64a3e2d303 100644 --- a/src/Perl6/World.pm +++ b/src/Perl6/World.pm @@ -1964,16 +1964,31 @@ class Perl6::World is HLL::World { my $success := 0; my $ex_t; my $coercer; - try { $ex_t := self.find_symbol(['X', 'Comp', 'AdHoc']); $success := 1 }; try { $coercer := self.find_symbol(['&COMP_EXCEPTION']); ++$success; }; - $err.rethrow unless $success == 2; - my $p6ex := $coercer($err); - nqp::bindattr($p6ex, $ex_t, '$!filename', + nqp::rethrow($err) unless $success; + my $p6ex := $coercer($err); + try { + $ex_t := self.find_symbol(['X', 'Comp']); + if nqp::istype($p6ex, $err) { + $p6ex.SET_FILE_LINE( + nqp::box_s(pir::find_caller_lex__ps('$?FILES'), + self.find_symbol(['Str'])), + nqp::box_i(HLL::Compiler.lineof($/.orig, $/.from), + self.find_symbol(['Int'])), + ); + $success++; + } + } + $p6ex.rethrow if $success == 2; + $success := 0; + try { $ex_t := self.find_symbol(['X', 'Comp', 'AdHoc']); ++$success }; + $p6ex.rethrow unless $success; + $p6ex.SET_FILE_LINE( nqp::box_s(pir::find_caller_lex__ps('$?FILES'), - self.find_symbol(['Str']))); - nqp::bindattr($p6ex, $ex_t, '$!line', + self.find_symbol(['Str'])), nqp::box_i(HLL::Compiler.lineof($/.orig, $/.from), - self.find_symbol(['Int']))); + self.find_symbol(['Int'])), + ); $p6ex.rethrow(); } } diff --git a/src/core/Exception.pm b/src/core/Exception.pm index a23a1af33a8..b5e2b990236 100644 --- a/src/core/Exception.pm +++ b/src/core/Exception.pm @@ -313,6 +313,10 @@ my role X::Comp is Exception { } $r; } + method SET_FILE_LINE($file, $line) { + $!filename = $file; + $!line = $line; + } } # XXX a hack for getting line numbers from exceptions from the metamodel