This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Skip warnable const folding outside warnings scope
Constant folding is not supposed to warn. If it would produce a warn-
ing, then it is skipped and the warning is deferred to run time.
This means the -w flag can affect constant folding:
$ ./perl -Ilib -MO=Concise -le 'use constant u=>undef; $a = u+1'
6 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 132 -e:1) v:{ ->3
5 <2> sassign vKS/2 ->6
3 <$> const[NV 1] s/FOLD ->4
- <1> ex-rv2sv sKRM*/1 ->5
4 <#> gvsv[*a] s ->5
-e syntax OK
$ ./perl -Ilib -MO=Concise -lwe 'use constant u=>undef; $a = u+1'
8 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 132 -e:1) v:{ ->3
7 <2> sassign vKS/2 ->8
5 <2> add[t2] sK/2 ->6
3 <$> const[NULL ] s*/FOLD ->4
4 <$> const[PVNV 1] s ->5
- <1> ex-rv2sv sKRM*/1 ->7
6 <#> gvsv[*a] s ->7
-e syntax OK
But the problem here is that the flag could be turned on at run time,
so if the folding happens because -w is off, then the behaviour
changes due to folding. It’s fine to do the folding here only when
warnings are lexically disabled, as that overrides any setting of -w.