Skip to content

Commit 4e22a3d

Browse files
committed
class.c: gracefully handle reader/writer after 'strict' error
Fixes #23511.
1 parent eb7679d commit 4e22a3d

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
@@ -1143,7 +1143,8 @@ apply_field_attribute_reader(pTHX_ PADNAME *pn, SV *value)
11431143
OP *nameop = newSVOP(OP_CONST, 0, value);
11441144

11451145
CV *cv = newATTRSUB(floor_ix, nameop, NULL, NULL, ops);
1146-
CvIsMETHOD_on(cv);
1146+
if (cv)
1147+
CvIsMETHOD_on(cv);
11471148
}
11481149

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

12431244
CV *cv = newATTRSUB(floor_ix, nameop, NULL, NULL, ops);
1244-
CvIsMETHOD_on(cv);
1245+
if (cv)
1246+
CvIsMETHOD_on(cv);
12451247
}
12461248

12471249
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 {
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)