From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: sub prototypes aren't enough...
Date: Wed, 17 Apr 2024 09:54:23 +0000 [thread overview]
Message-ID: <20240417095423.M903544@dcvr> (raw)
In-Reply-To: <20240417093401.M319057@dcvr>
Eric Wong <e@80x24.org> 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.
next prev parent reply other threads:[~2024-04-17 9:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-16 20:56 [PATCH 0/4] lei parallelism fixes Eric Wong
2024-04-16 20:56 ` [PATCH 1/4] v2 + lei/store: always wait for fast-import checkpoint Eric Wong
2024-04-16 20:56 ` [PATCH 2/4] lei: use ->barrier to commit to lei/store Eric Wong
2024-04-16 20:56 ` [PATCH 3/4] lei/store: stop shard workers + cat-file on idle Eric Wong
2024-04-17 9:34 ` [PATCH v2 " Eric Wong
2024-04-17 9:54 ` Eric Wong [this message]
2024-04-16 20:56 ` [PATCH 4/4] lei: use async barrier for --import-before Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240417095423.M903544@dcvr \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).