From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id F395B1F44D for ; Wed, 17 Apr 2024 09:54:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1713347664; bh=99Jze8Sd47ndtTfTJUrq86vUXJNFCyaKjc4RkU3uSLY=; h=Date:From:To:Subject:References:In-Reply-To:From; b=EPP63tbVeomwqLr0G8jLh0T6S/FBjPlQBqPv+3K6CaGhW+nTFq0/nhuJu+nc5Qxwv 4SQ5XLtlpdsTb3Jdw/jdugbxN99gZUkrjORbDd7Zn9aMFhXdUkj/MCZ0X0Od45jCjf O5xx7uxAb1jOJpB/rHGcurTTLktw8CMwhpzNjdiQ= Date: Wed, 17 Apr 2024 09:54:23 +0000 From: Eric Wong To: meta@public-inbox.org Subject: sub prototypes aren't enough... Message-ID: <20240417095423.M903544@dcvr> References: <20240416205629.3648894-1-e@80x24.org> <20240416205629.3648894-4-e@80x24.org> <20240417093401.M319057@dcvr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240417093401.M319057@dcvr> List-Id: Eric Wong 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.