diff --git a/op.c b/op.c index 7d5db41b58226..937d12ffa61b9 100644 --- a/op.c +++ b/op.c @@ -12416,6 +12416,8 @@ Perl_ck_eval(pTHX_ OP *o) PERL_ARGS_ASSERT_CK_EVAL; PL_hints |= HINT_BLOCK_SCOPE; + if(PL_prevailing_version != 0) + PL_hints |= HINT_LOCALIZE_HH; if (o->op_flags & OPf_KIDS) { SVOP * const kid = cSVOPx(cUNOPo->op_first); assert(kid); @@ -12457,6 +12459,7 @@ Perl_ck_eval(pTHX_ OP *o) && !(o->op_private & OPpEVAL_COPHH) && GvHV(PL_hintgv)) { /* Store a copy of %^H that pp_entereval can pick up. */ HV *hh = hv_copy_hints_hv(GvHV(PL_hintgv)); + hv_stores(hh, "CORE/prevailing_version", newSVuv(PL_prevailing_version)); OP *hhop; hhop = newSVOP(OP_HINTSEVAL, 0, MUTABLE_SV(hh)); /* append hhop to only child */ diff --git a/pp_ctl.c b/pp_ctl.c index 8c6c1a07723bc..6a1112038d5b7 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -4062,6 +4062,7 @@ S_doeval_compile(pTHX_ U8 gimme, CV* outside, U32 seq, HV *hh) else { PL_hints = saveop->op_private & OPpEVAL_COPHH ? oldcurcop->cop_hints : (U32)saveop->op_targ; + PL_prevailing_version = 0; /* we might change this below */ /* making 'use re eval' not be in scope when compiling the * qr/mabye_has_runtime_code_block/ ensures that we don't get @@ -4076,6 +4077,11 @@ S_doeval_compile(pTHX_ U8 gimme, CV* outside, U32 seq, HV *hh) SvREFCNT_dec(GvHV(PL_hintgv)); GvHV(PL_hintgv) = hh; FETCHFEATUREBITSHH(hh); + SV *versv, **svp; + if((svp = hv_fetchs(hh, "CORE/prevailing_version", 0)) && (versv = *svp) && SvOK(versv)) { + SAVEI16(PL_prevailing_version); + PL_prevailing_version = SvUV(versv); + } } } SAVECOMPILEWARNINGS(); diff --git a/t/lib/test_22121.pm b/t/lib/test_22121.pm new file mode 100644 index 0000000000000..8db663ce10377 --- /dev/null +++ b/t/lib/test_22121.pm @@ -0,0 +1,2 @@ +eval "use v5.14;"; +1; diff --git a/t/lib/warnings/op b/t/lib/warnings/op index f5505d33acb45..500370166a163 100644 --- a/t/lib/warnings/op +++ b/t/lib/warnings/op @@ -2180,3 +2180,9 @@ use v5.12; use v5.12; # expect no warning because same version EXPECT +######## +# GH #22121 +use v5.20; +use test_22121; +# expect no warning because different scope +EXPECT