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

[perl #126981] Possible regression using constant for hash key inperl 5.22+

Thread Next
From:
Chad Granum
Date:
December 21, 2015 18:26
Subject:
[perl #126981] Possible regression using constant for hash key inperl 5.22+
Message ID:
rt-4.0.18-9473-1450722347-501.126981-75-0@perl.org
# New Ticket Created by  Chad Granum 
# Please include the string:  [perl #126981]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=126981 >


This is a pattern that is used sometimes


> sub CONST() { 'some_key' };
> my $val = $hash->{+CONST};


This has a couple benefits, one of which is typo protection for hash key
lookups. This has worked as far back as I can test (5.8.1). It also still
works today in 5.22. However there is a possible bug that appears to have
been introduced between 5.20 and 5.22:

sub CONST() { 'some_key' };
> my $val = $hash->{+CONST_TYPO};


The above will fail on perl 5.8->5.20 with the following error:

 Bareword "CONST_TYPO" not allowed while "strict subs" in use at


However on 5.22 it compiles perfectly fine, and also does not issue any
warnings or errors at run-time. This is completely new in the 5.22 releases.

I am attaching a sample script to demonstrate it.

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