@@ -4468,11 +4468,14 @@ S_scan_const(pTHX_ char *start)
4468
4468
}
4469
4469
4470
4470
STATIC Size_t
4471
- S_is_existing_identifier (pTHX_ char * s , char * e , bool is_utf8 )
4471
+ S_is_existing_identifier (pTHX_ char * s , char * e , char sigil , bool is_utf8 )
4472
4472
{
4473
4473
/* This checks if the string from 's' to (e - 1) with utf8ness 'is_utf8' is
4474
- * an identifier known to the program. If so, it returns the length of
4475
- * the identifier. If not, it returns 0 */
4474
+ * an identifier known to the program of the type given by 'sigil'. So for
4475
+ * sigil '$', it checks for a scalar, etc. If so, it returns the length of
4476
+ * the identifier. If not, it returns 0
4477
+ *
4478
+ * It overwrites s[0], restoring it before returning */
4476
4479
4477
4480
ptrdiff_t size = e - s ;
4478
4481
@@ -4493,26 +4496,30 @@ S_is_existing_identifier(pTHX_ char *s, char *e, bool is_utf8)
4493
4496
char * tmpbuf ;
4494
4497
Newx (tmpbuf , size , char );
4495
4498
4499
+ const char save_sigil = s [0 ];
4500
+ s [0 ] = sigil ;
4501
+
4496
4502
/* scan_ident doesn't return the sigil, but pad_findmy_pv wants it */
4497
4503
scan_ident (s , tmpbuf + 1 , size - 1 , FALSE);
4498
- tmpbuf [0 ] = s [ 0 ] ;
4504
+ tmpbuf [0 ] = sigil ;
4499
4505
4500
4506
Size_t len = strlen (tmpbuf ) - 1 ; /* Doesn't include sigil */
4501
4507
4502
4508
PADOFFSET slot = pad_findmy_pv (tmpbuf , 0 );
4503
4509
if ( slot == NOT_IN_PAD
4504
4510
&& ! gv_fetchpvn_flags (tmpbuf + 1 , len ,
4505
4511
(is_utf8 ) ? SVf_UTF8 : 0 ,
4506
- (s [ 0 ] == '@' )
4512
+ (sigil == '@' )
4507
4513
? SVt_PVAV
4508
- : (s [ 0 ] == '&' )
4514
+ : (sigil == '&' )
4509
4515
? SVt_PVCV
4510
4516
: SVt_PV ))
4511
4517
{
4512
4518
len = 0 ;
4513
4519
}
4514
4520
4515
4521
Safefree (tmpbuf );
4522
+ s [0 ] = save_sigil ;
4516
4523
4517
4524
return len ;
4518
4525
}
@@ -4695,7 +4702,7 @@ S_intuit_more(pTHX_ char *s, char *e)
4695
4702
* identifier already found in the program by that name and type.
4696
4703
* If so, strongly suspect this isn't a character class */
4697
4704
if (isWORDCHAR_lazy_if_safe (s + 1 , PL_bufend , UTF )) {
4698
- Size_t len = is_existing_identifier (s , PL_bufend , UTF );
4705
+ Size_t len = is_existing_identifier (s , PL_bufend , s [ 0 ], UTF );
4699
4706
4700
4707
/* We only mark this as strongly suspect subscript if the
4701
4708
* identifier is multi-char; otherwise mildly suspect (even if
0 commit comments