Skip to content

Commit 5dcc57d

Browse files
committed
class.c: gracefully handle reader/writer after 'strict' error
Fixes #23511.
1 parent 463db48 commit 5dcc57d

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6002,6 +6002,7 @@ t/class/construct.t See if class constructors work
60026002
t/class/destruct.t See if class destruction works
60036003
t/class/field.t See if class field declarations work
60046004
t/class/gh22169.t Test defining a class that previously failed to define
6005+
t/class/gh23511.t Test defining a reader after a strict 'vars' violation
60056006
t/class/inherit.t See if class inheritance works
60066007
t/class/method.t See if class method declarations work
60076008
t/class/phasers.t See if class phaser blocks work

class.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,8 @@ apply_field_attribute_reader(pTHX_ PADNAME *pn, SV *value)
11401140
OP *nameop = newSVOP(OP_CONST, 0, value);
11411141

11421142
CV *cv = newATTRSUB(floor_ix, nameop, NULL, NULL, ops);
1143-
CvIsMETHOD_on(cv);
1143+
if (cv)
1144+
CvIsMETHOD_on(cv);
11441145
}
11451146

11461147
/* If '@_' is called "snail", then elements of it can be called "slugs"; i.e.
@@ -1238,7 +1239,8 @@ apply_field_attribute_writer(pTHX_ PADNAME *pn, SV *value)
12381239
OP *nameop = newSVOP(OP_CONST, 0, value);
12391240

12401241
CV *cv = newATTRSUB(floor_ix, nameop, NULL, NULL, ops);
1241-
CvIsMETHOD_on(cv);
1242+
if (cv)
1243+
CvIsMETHOD_on(cv);
12421244
}
12431245

12441246
static struct {

t/class/gh23511.t

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!./perl
2+
3+
BEGIN {
4+
chdir 't' if -d 't';
5+
require './test.pl';
6+
set_up_inc('../lib');
7+
}
8+
9+
use v5.36;
10+
use feature 'class';
11+
no warnings 'experimental::class';
12+
13+
# this used to segfault: GH #23511
14+
eval <<'CLASS';
15+
class MyTest_r {
16+
$id = 6;
17+
field $f1 :reader;
18+
field $f2 :writer;
19+
}
20+
CLASS
21+
like $@, qr/^Global symbol "\$id" requires explicit package name /, "we get the expected 'undeclared variable' error";
22+
23+
done_testing;

0 commit comments

Comments
 (0)