File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -15242,16 +15242,24 @@ Perl_ck_length(pTHX_ OP *o)
15242
15242
OP *
15243
15243
Perl_ck_isa(pTHX_ OP *o)
15244
15244
{
15245
- OP *classop = cBINOPo->op_last;
15246
-
15247
15245
PERL_ARGS_ASSERT_CK_ISA;
15248
15246
15247
+ OP *const classop = cBINOPo->op_last;
15248
+
15249
15249
/* Convert barename into PV */
15250
15250
if(classop->op_type == OP_CONST && classop->op_private & OPpCONST_BARE) {
15251
15251
/* TODO: Optionally convert package to raw HV here */
15252
15252
classop->op_private &= ~(OPpCONST_BARE|OPpCONST_STRICT);
15253
15253
}
15254
15254
15255
+ OP *const objop = cBINOPo->op_first;
15256
+ /* !$x isa Some::Class # probably meant !($x isa Some::Class) */
15257
+ if (objop->op_type == OP_NOT && !(objop->op_flags & OPf_PARENS)) {
15258
+ Perl_ck_warner(aTHX_ packWARN(WARN_PRECEDENCE),
15259
+ "Possible precedence problem on isa operator"
15260
+ );
15261
+ }
15262
+
15255
15263
return o;
15256
15264
}
15257
15265
Original file line number Diff line number Diff line change @@ -5508,6 +5508,19 @@ If instead you intended to match the word 'foo' at the end of the line
5508
5508
followed by whitespace and the word 'bar' on the next line then you can use
5509
5509
C<m/$(?)\/> (for example: C<m/foo$(?)\s+bar/>).
5510
5510
5511
+ =item Possible precedence problem on isa operator
5512
+
5513
+ (W precedence) You wrote something like
5514
+
5515
+ !$obj isa Some::Class
5516
+
5517
+ but because C<!> has higher precedence than C<isa>, this is interpreted as
5518
+ C<(!$obj) isa Some::Class>, which checks whether a boolean is an instance of
5519
+ C<Some::Class>. If you want to negate the result of C<isa> instead, use one of:
5520
+
5521
+ !($obj isa Some::Class) # explicit parentheses
5522
+ not $obj isa Some::Class # low-precedence 'not' operator
5523
+
5511
5524
=item Possible unintended interpolation of %s in string
5512
5525
5513
5526
(W ambiguous) You said something like '@foo' in a double-quoted string
Original file line number Diff line number Diff line change @@ -1577,6 +1577,18 @@ Possible precedence problem on bitwise |. operator at - line 26.
1577
1577
Possible precedence problem on bitwise &. operator at - line 27.
1578
1578
########
1579
1579
# op.c
1580
+ use warnings 'precedence';
1581
+ use feature 'isa';
1582
+ $a = !$b isa Some::Class; # should warn
1583
+ $a = (!$b) isa Some::Class;
1584
+ $a = !($b) isa Some::Class; # should warn
1585
+ $a = !($b isa Some::Class);
1586
+ $a = not $b isa Some::Class;
1587
+ EXPECT
1588
+ Possible precedence problem on isa operator at - line 4.
1589
+ Possible precedence problem on isa operator at - line 6.
1590
+ ########
1591
+ # op.c
1580
1592
use integer;
1581
1593
use warnings 'precedence';
1582
1594
$a = $b & $c == $d;
You can’t perform that action at this time.
0 commit comments