File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -979,6 +979,9 @@ apply_field_attribute_reader(pTHX_ PADNAME *pn, SV *value)
979
979
/* Default to name minus the sigil */
980
980
value = newSVpvn_utf8 (PadnamePV (pn ) + 1 , PadnameLEN (pn ) - 1 , PadnameUTF8 (pn ));
981
981
982
+ if (!valid_identifier_sv (value ))
983
+ croak ("%" SVf_QUOTEDPREFIX " is not a valid name for a generated method" , value );
984
+
982
985
PADOFFSET fieldix = PadnameFIELDINFO (pn )-> fieldix ;
983
986
984
987
I32 floor_ix = start_subparse (FALSE, 0 );
Original file line number Diff line number Diff line change @@ -3499,6 +3499,13 @@ should use the printf/sprintf functions instead.
3499
3499
overload::constant needs to be a code reference. Either
3500
3500
an anonymous subroutine, or a reference to a subroutine.
3501
3501
3502
+ =item "%s" is not a valid name for a generated method
3503
+
3504
+ (F) A custom method name was passed to an attribute on a field, such as
3505
+ C<:reader>, which creates a new method. These generated methods must have
3506
+ valid names, but the value given to the attribute would result in an
3507
+ invalid name.
3508
+
3502
3509
=item '%s' is not an overloadable type
3503
3510
3504
3511
(W overload) You tried to overload a constant type the overload package is
Original file line number Diff line number Diff line change @@ -155,3 +155,13 @@ class C { BEGIN { C->new; } };
155
155
EXPECT
156
156
Cannot create an object of incomplete class "C" at - line 4.
157
157
BEGIN failed--compilation aborted at - line 4.
158
+ ########
159
+ # Invalid method name for :reader attribute
160
+ use v5.36;
161
+ use feature 'class';
162
+ no warnings 'experimental::class';
163
+ class XXX {
164
+ field $x :reader(abc-def);
165
+ }
166
+ EXPECT
167
+ "abc-def" is not a valid name for a generated method at - line 6.
You can’t perform that action at this time.
0 commit comments