Skip to content

Commit 3d03338

Browse files
author
Zefram
committed
warn on $a.$b.$c in void context
$a.$b.$c gets transformed early on to execute as ($a.$b).=$c, which didn't warn about void context becuase .= looks like a useful side effect. Happily, the recently-added OPpCONCAT_NESTED flag identifies that this has happened. Make scalarvoid() pay attention to this flag when a concat op is put into void context. Fixes [perl #6997]
1 parent 9b568b5 commit 3d03338

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

op.c

+5
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,11 @@ Perl_scalarvoid(pTHX_ OP *arg)
19491949
if (o->op_type == OP_REPEAT)
19501950
scalar(cBINOPo->op_first);
19511951
goto func_ops;
1952+
case OP_CONCAT:
1953+
if ((o->op_flags & OPf_STACKED) &&
1954+
!(o->op_private & OPpCONCAT_NESTED))
1955+
break;
1956+
goto func_ops;
19521957
case OP_SUBSTR:
19531958
if (o->op_private == 4)
19541959
break;

t/lib/warnings/op

+9
Original file line numberDiff line numberDiff line change
@@ -2065,3 +2065,12 @@ use warnings;
20652065
$_="3.14159";
20662066
tr/0-9/\x{6F0}-\x{6F9}/;
20672067
EXPECT
2068+
########
2069+
# Useless use of concatenation should appear for any number of args
2070+
use warnings;
2071+
($a, $b, $c) = (42)x3;
2072+
$a.$b;
2073+
$a.$b.$c;
2074+
EXPECT
2075+
Useless use of concatenation (.) or string in void context at - line 4.
2076+
Useless use of concatenation (.) or string in void context at - line 5.

0 commit comments

Comments
 (0)