Skip to content

Commit

Permalink
Report deprecated subs/methods that are hidden-from-backtrace
Browse files Browse the repository at this point in the history
Issue described in #5055

Fixed by adding a :reveal option to Backtrace.next-interesting-index
that will **not** skip entries that have "is hidden-from-backtrace".

Also properly sort line numbers that were found.
  • Loading branch information
lizmat committed Sep 15, 2022
1 parent d0ec99a commit 43a6575
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/core.c/Backtrace.pm6
Expand Up @@ -227,14 +227,17 @@ my class Backtrace {
}

method next-interesting-index(Backtrace:D:
Int $idx is copy = 0, :$named, :$noproto, :$setting) {
Int $idx is copy = 0, :$named, :$noproto, :$setting, :$reveal) {
++$idx;

while self.AT-POS($idx++) -> $cand {
next if $cand.is-hidden; # hidden is never interesting
next if !$reveal # keep hidden
&& $cand.is-hidden; # if hidden from backtrace

next if $noproto # no proto's please
&& nqp::can($cand,"is_dispatcher")
&& $cand.code.is_dispatcher; # if a dispatcher

next if !$setting # no settings please
&& $cand.is-setting; # and in setting

Expand Down
9 changes: 5 additions & 4 deletions src/core.c/Deprecations.pm6
Expand Up @@ -44,8 +44,9 @@ class Deprecation {
my $package = $.package ?? "(from $.package) " !! "";
my $message = $type ~ $name ~ $package ~ "seen at:\n";
for %.callsites.kv -> $file, $lines {
$message ~=
" $file, line{ 's' if +$lines > 1 } {$lines.keys.sort.join(',')}\n";
$message ~= " $file, line{ 's' if +$lines > 1 } {
$lines.keys.sort(*.Int).join(',')
}\n";
if $.from or $.removed {
$message ~= $.from
?? "Deprecated since v$.from, will be removed"
Expand Down Expand Up @@ -85,10 +86,10 @@ class Rakudo::Deprecations {
my $bt = Backtrace.new;
my $deprecated =
#?if !js
$bt[ my $index = $bt.next-interesting-index(1, :named, :setting) // 0 ];
$bt[ my $index = $bt.next-interesting-index(1, :named, :setting, :reveal) // 0 ];
#?endif
#?if js
$bt[ my $index = $bt.next-interesting-index(2, :named, :setting) // 0 ];
$bt[ my $index = $bt.next-interesting-index(2, :named, :setting, :reveal) // 0 ];
#?endif

if $up ~~ Whatever {
Expand Down

0 comments on commit 43a6575

Please sign in to comment.