@@ -4468,11 +4468,14 @@ S_scan_const(pTHX_ char *start)
44684468}
44694469
44704470STATIC 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 )
44724472{
44734473 /* 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 */
44764479
44774480 ptrdiff_t size = e - s ;
44784481
@@ -4493,26 +4496,30 @@ S_is_existing_identifier(pTHX_ char *s, char *e, bool is_utf8)
44934496 char * tmpbuf ;
44944497 Newx (tmpbuf , size , char );
44954498
4499+ const char save_sigil = s [0 ];
4500+ s [0 ] = sigil ;
4501+
44964502 /* scan_ident doesn't return the sigil, but pad_findmy_pv wants it */
44974503 scan_ident (s , tmpbuf + 1 , size - 1 , FALSE);
4498- tmpbuf [0 ] = s [ 0 ] ;
4504+ tmpbuf [0 ] = sigil ;
44994505
45004506 Size_t len = strlen (tmpbuf ) - 1 ; /* Doesn't include sigil */
45014507
45024508 PADOFFSET slot = pad_findmy_pv (tmpbuf , 0 );
45034509 if ( slot == NOT_IN_PAD
45044510 && ! gv_fetchpvn_flags (tmpbuf + 1 , len ,
45054511 (is_utf8 ) ? SVf_UTF8 : 0 ,
4506- (s [ 0 ] == '@' )
4512+ (sigil == '@' )
45074513 ? SVt_PVAV
4508- : (s [ 0 ] == '&' )
4514+ : (sigil == '&' )
45094515 ? SVt_PVCV
45104516 : SVt_PV ))
45114517 {
45124518 len = 0 ;
45134519 }
45144520
45154521 Safefree (tmpbuf );
4522+ s [0 ] = save_sigil ;
45164523
45174524 return len ;
45184525}
@@ -4695,7 +4702,7 @@ S_intuit_more(pTHX_ char *s, char *e)
46954702 * identifier already found in the program by that name and type.
46964703 * If so, strongly suspect this isn't a character class */
46974704 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 );
46994706
47004707 /* We only mark this as strongly suspect subscript if the
47014708 * identifier is multi-char; otherwise mildly suspect (even if
0 commit comments