Eric Wong <[email protected]> wrote:
> v2 fixes an incorrect call to add_uniq_timer. Sometimes I wish Perl
> could have more static type||arg checking, but it's probably still
> better than other scripting languages...
Fwiw, this would work for all current callers, AFAIK:
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index a6fec954..52b89247 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -117,9 +117,9 @@ sub _add_named_timer {
die "Shouldn't get here.";
}
-sub add_timer { _add_named_timer(undef, @_) }
+sub add_timer ($&;@) { _add_named_timer(undef, @_) }
-sub add_uniq_timer { # ($name, $secs, $coderef, @args) = @_;
+sub add_uniq_timer ($$&;@) { # ($name, $secs, $coderef, @args) = @_;
$UniqTimer{$_[0]} //= _add_named_timer(@_);
}
... But the above falls short if somebody were to pass a scalar which
references CODE:
my $foo = sub {};
add_timer 5, $foo; # this valid code fails with the above patch
add_timer 5, sub {}; # this works as expected
So AFAIK Perl has no way to detect argument type bugs like this
reliably at compile time.