develooper Front page | perl.perl5.porters | Postings from May 2019

[perl #134072] sub prototypes not tracking refalias \&foo = \&bar

From:
Tony Cook via RT
Date:
May 15, 2019 06:09
Subject:
[perl #134072] sub prototypes not tracking refalias \&foo = \&bar
Message ID:
rt-4.0.24-4335-1557900578-1188.134072-15-0@perl.org
On Tue, 30 Apr 2019 16:50:20 -0700, jim.avera@gmail.com wrote:
> Not sure whether this is intended behavior, but just in case it's
> not...
> 
> The refalias
>   \&foo = \&bar
> is documented as "foo() now means bar()", but it doesn't entirely:
> 
> In subsequently-compiled code, the compiler still wants calls
> to foo() to match the old foo's prototype, not the prototype of bar.
> 
> 
> #!/usr/bin/perl
> use strict; use warnings; use v5.22.0;
> 
> use feature 'refaliasing';
> no warnings 'experimental::refaliasing';
> 
> sub foo($$$$) { }
> sub bar($) { }
> 
> BEGIN{ \&foo = \&bar; }
> 
> foo(1);  # Gets "Not enough arguments for main::foo"

Fix attached.

With the fix your code produces:

$ ./perl -Ilib ../134072.pl
Subroutine main::foo redefined at ../134072.pl line 11.
Prototype mismatch: sub main::foo ($$$$) vs ($) at ../134072.pl line 11.
bar

Tony

Tony


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=134072



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About