develooper Front page | perl.perl5.porters | Postings from December 2011

[perl #102486] strict subs fails with lvalue subroutines

Thread Next
From:
Father Chrysostomos via RT
Date:
December 26, 2011 13:47
Subject:
[perl #102486] strict subs fails with lvalue subroutines
Message ID:
rt-3.6.HEAD-14510-1324936050-1440.102486-15-0@perl.org
On Sun Oct 30 15:28:32 2011, asg wrote:
> sorry, gmail mangled the whitespace:
> 
> Subject: strict subs fails with lvalue subroutines
> Message-Id: <5.15.3_4541_1318900144@linux-op1p>
> Reply-To: asg@cpan.org
> To: perlbug@perl.org
> From: asg@cpan.org
> 
> 
> This is a bug report for perl from asg@cpan.org,
> generated with the help of perlbug 1.39 running under perl 5.15.3.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> the test file:
> 
>     #!/usr/bin/env perl
> 
>     use warnings;
>     use strict;
> 
>     print "perl v$]\n---\n";
> 
>     sub abc_string {
>         my $x = die 'abc_string called';
>     }
>     sub abc_string_lvalue :lvalue {
>         my $x = die 'abc_string_lvalue called';
>     }
>     sub abc {
>         my $x = "abc_string@_";
>         &$x
>     }
>     sub abc_lvalue :lvalue {
>         my $x = "abc_string@_";
>         &$x
>     }
>     eval {abc                 ; 1} or print "abc died:
> $@\n";
>     eval {abc_lvalue          ; 1} or print "abc_lvalue died:
> $@\n";
>     eval {abc        '_lvalue'; 1} or print "abc 'lvalue' died:
> $@\n";
>     eval {abc_lvalue '_lvalue'; 1} or print "abc_lvalue '_lvalue'
> died:
> $@\n";
> 
> results in:
> 
>     perl v5.015003
>     ---
>     abc died:                  Can't use string ("abc_string") as a
> subroutine ref while "strict refs" in use at test.pl line 16.
> 
>     abc_lvalue died:           Can't modify non-lvalue subroutine call
> at test.pl line 20.
> 
>     abc 'lvalue' died:         Can't use string ("abc_string_lvalue")
> as
> a subroutine ref while "strict refs" in use at test.pl line 16.
> 
>     abc_lvalue '_lvalue' died: abc_string_lvalue called at test.pl
> line 12.
> 
> ---
> 
> the two abc_lvalue() calls should die from "strict refs" but instead
> both continue past and fail for other reasons.
> 
> the bug has been observed in perl 5.10.1 and 5.15.3 (the latter of
> which
> is shown below).

The original lvalue sub implementation was so wrong I practically
rewrote it a few months ago.  This is one part I didn’t really look at,
because all the tests were passing.  Now that I look at it, I see
multiple problems with it.

Your test case exhibits two bugs, not one (the second call should not be
dying with ‘Can’t assign to non-lvalue subroutine’, even with strictures
off).

In trying to fix it, I found two more.

Details are in commit da1dff9483.

I deleted about forty lines and added three (not counting tests),
thereby fixing four bugs.  That’s something, isn’t it?


-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=102486

Thread Next


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