Skip Menu |
Report information
Id: 127877
Status: resolved
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: pushtaev.vm [at] gmail.com
Cc: ivan.yazykov [at] gmail.com
AdminCc:

Operating System: (no value)
PatchStatus: (no value)
Severity: low
Type: unknown
Perl Version: (no value)
Fixed In: (no value)

Attachments
0001-perl-127877-Emit-undef-warning-on-sassign-concat.patch



Subject: Concat with uninitialized vars
CC: ivan.yazykov [...] gmail.com
Download (untitled) / with headers
text/plain 2.1k
We discovered that `my` and `our` variables behave differently in terms of using uninitialized vars in concatenation. Try this: perl -e 'use warnings q{uninitialized}; my $x; $x .= "xxx"' perl -e 'use warnings q{uninitialized}; my $x; $x = $x . "xxx"' perl -e 'use warnings q{uninitialized}; my $x; $x .= "xxx" . undef' perl -e 'use warnings q{uninitialized}; my $x; $x = $x . "xxx" . undef' perl -e 'use warnings q{uninitialized}; our $x; $x .= "xxx"' perl -e 'use warnings q{uninitialized}; our $x; $x = $x . "xxx"' perl -e 'use warnings q{uninitialized}; our $x; $x .= "xxx" . undef' perl -e 'use warnings q{uninitialized}; our $x; $x = $x . "xxx" . undef' Get this: 1) perl -e 'use warnings q{uninitialized}; my $x; $x .= "xxx"' 2) perl -e 'use warnings q{uninitialized}; my $x; $x = $x . "xxx"' # None here. WHY!? 3) perl -e 'use warnings q{uninitialized}; my $x; $x .= "xxx" . undef' Use of uninitialized value in concatenation (.) or string at -e line 1. 4) perl -e 'use warnings q{uninitialized}; my $x; $x = $x . "xxx" . undef' Use of uninitialized value $x in concatenation (.) or string at -e line 1. Use of uninitialized value in concatenation (.) or string at -e line 1. 5) perl -e 'use warnings q{uninitialized}; our $x; $x .= "xxx"' 6) perl -e 'use warnings q{uninitialized}; our $x; $x = $x . "xxx"' Use of uninitialized value $x in concatenation (.) or string at -e line 1. 7) perl -e 'use warnings q{uninitialized}; our $x; $x .= "xxx" . undef' Use of uninitialized value in concatenation (.) or string at -e line 1. 8) perl -e 'use warnings q{uninitialized}; our $x; $x = $x . "xxx" . undef' Use of uninitialized value $x in concatenation (.) or string at -e line 1. Use of uninitialized value in concatenation (.) or string at -e line 1. There is no consistency in this behavior: * (2) and (6) behave differently though the only difference is `my` and `our`. * If (2) doesn't throw the warning, why does (4) throw TWO of them? Btw, there is no such problem with the addition (`+`). P.S. I also don't quite understand why `.=` doesn't throw any warnings, but this behavior is understandable and consistent, so no problem here. P.P.S. The problem was originally discovered by ivan.yazykov@gmail.com
From: demerphq <demerphq [...] gmail.com>
To: Perl5 Porteros <perl5-porters [...] perl.org>
Date: Mon, 11 Apr 2016 14:00:45 +0200
Subject: Re: [perl #127877] Concat with uninitialized vars
CC: "bugs-bitbucket [...] rt.perl.org" <bugs-bitbucket [...] rt.perl.org>
Download (untitled) / with headers
text/plain 3.4k
On 11 April 2016 at 12:56, Vadim Pushtaev <perlbug-followup@perl.org> wrote: Show quoted text
> # New Ticket Created by Vadim Pushtaev > # Please include the string: [perl #127877] > # in the subject line of all future correspondence about this issue. > # <URL: https://rt.perl.org/Ticket/Display.html?id=127877 > > > > We discovered that `my` and `our` variables behave differently in terms of using uninitialized vars in concatenation. > > Try this: > > perl -e 'use warnings q{uninitialized}; my $x; $x .= "xxx"' > perl -e 'use warnings q{uninitialized}; my $x; $x = $x . "xxx"' > perl -e 'use warnings q{uninitialized}; my $x; $x .= "xxx" . undef' > perl -e 'use warnings q{uninitialized}; my $x; $x = $x . "xxx" . undef' > perl -e 'use warnings q{uninitialized}; our $x; $x .= "xxx"' > perl -e 'use warnings q{uninitialized}; our $x; $x = $x . "xxx"' > perl -e 'use warnings q{uninitialized}; our $x; $x .= "xxx" . undef' > perl -e 'use warnings q{uninitialized}; our $x; $x = $x . "xxx" . undef' > > Get this: > > 1) perl -e 'use warnings q{uninitialized}; my $x; $x .= "xxx"'
This is expected. Show quoted text
> > 2) perl -e 'use warnings q{uninitialized}; my $x; $x = $x . "xxx"' > # None here. WHY!?
Yes, agreed. I find this not warning to be odd, and a bug. I wonder if it is a regression. Show quoted text
> > 3) perl -e 'use warnings q{uninitialized}; my $x; $x .= "xxx" . undef' > Use of uninitialized value in concatenation (.) or string at -e line 1.
This is expected. Show quoted text
> > 4) perl -e 'use warnings q{uninitialized}; my $x; $x = $x . "xxx" . undef' > Use of uninitialized value $x in concatenation (.) or string at -e line 1. > Use of uninitialized value in concatenation (.) or string at -e line 1.
This is expected. Show quoted text
> > 5) perl -e 'use warnings q{uninitialized}; our $x; $x .= "xxx"'
This is expected. Show quoted text
> 6) perl -e 'use warnings q{uninitialized}; our $x; $x = $x . "xxx"' > Use of uninitialized value $x in concatenation (.) or string at -e line 1.
This is expected. And is what I expect #2 to do. Show quoted text
> 7) perl -e 'use warnings q{uninitialized}; our $x; $x .= "xxx" . undef' > Use of uninitialized value in concatenation (.) or string at -e line 1.
This is expected. Show quoted text
> 8) perl -e 'use warnings q{uninitialized}; our $x; $x = $x . "xxx" . undef' > Use of uninitialized value $x in concatenation (.) or string at -e line 1. > Use of uninitialized value in concatenation (.) or string at -e line 1.
Also expected. Show quoted text
> There is no consistency in this behavior: > * (2) and (6) behave differently though the only difference is `my` and `our`.
Yes, I agree this is a bug. Show quoted text
> * If (2) doesn't throw the warning, why does (4) throw TWO of them?
2 is buggy. What it does should not be used to determine what 4 does. We get two warnings because there are two undefined values involved. my $x; $x = $x . "xxx" . undef The first is $x starting off undefined, and the second is the undef call. Show quoted text
> Btw, there is no such problem with the addition (`+`).
Interesting. Show quoted text
> P.S. I also don't quite understand why `.=` doesn't throw any warnings, but this behavior is understandable and consistent, so no problem here.
.= is a mutator. Most mutators DONT warn on uninitialized value on the lhs but a few do (IIRC it DWIM pretty well). This is documented somewhere in the perldocs. That is why ++ does not warn, and why +=1 doesnt warn, etc. So the only bug here is that perl -e 'use warnings q{uninitialized}; my $x; $x = $x . "xxx"' does not warn when it should. Yves -- perl -Mre=debug -e "/just|another|perl|hacker/"
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 3.7k
On Mon Apr 11 05:01:17 2016, demerphq wrote: Show quoted text
> On 11 April 2016 at 12:56, Vadim Pushtaev <perlbug-followup@perl.org> > wrote:
> > # New Ticket Created by Vadim Pushtaev > > # Please include the string: [perl #127877] > > # in the subject line of all future correspondence about this issue. > > # <URL: https://rt.perl.org/Ticket/Display.html?id=127877 > > > > > > > We discovered that `my` and `our` variables behave differently in > > terms of using uninitialized vars in concatenation. > > > > Try this: > > > > perl -e 'use warnings q{uninitialized}; my $x; $x .= "xxx"' > > perl -e 'use warnings q{uninitialized}; my $x; $x = $x . "xxx"' > > perl -e 'use warnings q{uninitialized}; my $x; $x .= "xxx" . undef' > > perl -e 'use warnings q{uninitialized}; my $x; $x = $x . "xxx" . > > undef' > > perl -e 'use warnings q{uninitialized}; our $x; $x .= "xxx"' > > perl -e 'use warnings q{uninitialized}; our $x; $x = $x . "xxx"' > > perl -e 'use warnings q{uninitialized}; our $x; $x .= "xxx" . undef' > > perl -e 'use warnings q{uninitialized}; our $x; $x = $x . "xxx" . > > undef' > > > > Get this: > > > > 1) perl -e 'use warnings q{uninitialized}; my $x; $x .= "xxx"'
> > This is expected. >
> > > > 2) perl -e 'use warnings q{uninitialized}; my $x; $x = $x . "xxx"' > > # None here. WHY!?
> > Yes, agreed. I find this not warning to be odd, and a bug. I wonder if > it is a regression. >
> > > > 3) perl -e 'use warnings q{uninitialized}; my $x; $x .= "xxx" . > > undef' > > Use of uninitialized value in concatenation (.) or string at -e line > > 1.
> > This is expected. >
> > > > 4) perl -e 'use warnings q{uninitialized}; my $x; $x = $x . "xxx" . > > undef' > > Use of uninitialized value $x in concatenation (.) or string at -e > > line 1. > > Use of uninitialized value in concatenation (.) or string at -e line > > 1.
> > This is expected. >
> > > > 5) perl -e 'use warnings q{uninitialized}; our $x; $x .= "xxx"'
> > This is expected. >
> > 6) perl -e 'use warnings q{uninitialized}; our $x; $x = $x . "xxx"' > > Use of uninitialized value $x in concatenation (.) or string at -e > > line 1.
> > This is expected. And is what I expect #2 to do. >
> > 7) perl -e 'use warnings q{uninitialized}; our $x; $x .= "xxx" . > > undef' > > Use of uninitialized value in concatenation (.) or string at -e line > > 1.
> > This is expected. >
> > 8) perl -e 'use warnings q{uninitialized}; our $x; $x = $x . "xxx" . > > undef' > > Use of uninitialized value $x in concatenation (.) or string at -e > > line 1. > > Use of uninitialized value in concatenation (.) or string at -e line > > 1.
> > Also expected. >
> > There is no consistency in this behavior: > > * (2) and (6) behave differently though the only difference is `my` > > and `our`.
> > Yes, I agree this is a bug. >
> > * If (2) doesn't throw the warning, why does (4) throw TWO of them?
> > 2 is buggy. What it does should not be used to determine what 4 does. > > We get two warnings because there are two undefined values involved.
Yes, that's exactly what I meant. Show quoted text
> my $x; $x = $x . "xxx" . undef > > The first is $x starting off undefined, and the second is the undef > call. >
> > Btw, there is no such problem with the addition (`+`).
> > Interesting. >
> > P.S. I also don't quite understand why `.=` doesn't throw any > > warnings, but this behavior is understandable and consistent, so no > > problem here.
> > .= is a mutator. Most mutators DONT warn on uninitialized value on the > lhs but a few do (IIRC it DWIM pretty well). This is documented > somewhere in the perldocs.
I know it's unrelated, but I still can't find it in perdocs. Show quoted text
> That is why ++ does not warn, and why +=1 doesnt warn, etc. > > So the only bug here is that > > perl -e 'use warnings q{uninitialized}; my $x; $x = $x . "xxx"' > > does not warn when it should. > > Yves
CC: Perl5 Porteros <perl5-porters [...] perl.org>
Subject: Re: [perl #127877] Concat with uninitialized vars
Date: Mon, 11 Apr 2016 14:45:10 +0200
To: Perl RT Bug Tracker <perlbug-followup [...] perl.org>
From: demerphq <demerphq [...] gmail.com>
Download (untitled) / with headers
text/plain 637b
On 11 April 2016 at 14:17, Vadim Pushtaev via RT <perlbug-followup@perl.org> wrote: Show quoted text
> On Mon Apr 11 05:01:17 2016, demerphq wrote:
>> .= is a mutator. Most mutators DONT warn on uninitialized value on the >> lhs but a few do (IIRC it DWIM pretty well). This is documented >> somewhere in the perldocs.
> > I know it's unrelated, but I still can't find it in perdocs.
It is in perlsyn, section "Declarations": Operators such as C<++>, C<-->, C<+=>, C<-=>, and C<.=>, that operate on undefined variables such as: undef $a; $a++; are also always exempt from such warnings. -- perl -Mre=debug -e "/just|another|perl|hacker/"
Subject: Re: [perl #127877] Concat with uninitialized vars
From: Aaron Crane <arc [...] cpan.org>
CC: Perl5 Porteros <perl5-porters [...] perl.org>, "bugs-bitbucket [...] rt.perl.org" <bugs-bitbucket [...] rt.perl.org>
To: demerphq <demerphq [...] gmail.com>
Date: Sun, 8 May 2016 18:25:20 +0100
Download (untitled) / with headers
text/plain 275b
demerphq <demerphq@gmail.com> wrote: Show quoted text
> So the only bug here is that > > perl -e 'use warnings q{uninitialized}; my $x; $x = $x . "xxx"' > > does not warn when it should.
Fix attached; I plan to apply it early in the 5.25 cycle. -- Aaron Crane ** http://aaroncrane.co.uk/

Message body is not shown because sender requested not to inline it.

RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 116b
Applied as 51f69a247f06354aa055df45451b8b569803f561; resolving ticket. -- Aaron Crane ** http://aaroncrane.co.uk/
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 362b
On Sun May 08 10:26:07 2016, arc wrote: Show quoted text
> demerphq <demerphq@gmail.com> wrote:
> > So the only bug here is that > > > > perl -e 'use warnings q{uninitialized}; my $x; $x = $x . "xxx"' > > > > does not warn when it should.
> > Fix attached; I plan to apply it early in the 5.25 cycle. >
Thanks! We actually suspected that some optimization trick involed :).


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org