Skip to content

Commit 332f594

Browse files
committed
class.c: gracefully handle reader definition after 'strict' error
Fixes #23511.
1 parent 463db48 commit 332f594

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
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: 2 additions & 1 deletion
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.

t/class/gh23511.t

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 $name :reader;
18+
}
19+
CLASS
20+
like $@, qr/^Global symbol "\$id" requires explicit package name /, "we get the expected 'undeclared variable' error";
21+
22+
done_testing;

0 commit comments

Comments
 (0)