$ perl -MO=Deparse -e 'use strict; print \&foo'
-e syntax OK
The deparsing unnecessarily includes package qualification. The deparser
generally avoids unnecessary qualification, for example it doesn't qualify
the corresponding glob ref. So this seems undesirable behaviour, which
should probably be changed.
The conditions for this to happen are an "&foo" reference to a sub,
where the sub is in the current package, the sub is not being called,
"use strict 'vars'" is in effect, and no lexical sub of the same name
is in scope. It has not always been this way: prior to Perl 5.21.7 the
package qualification was not included. Crucially, this changed at the
same time as a related bugfix: in the early days of lexical subs the
deparser would emit "&foo" for a package sub even if it was shadowed by
a lexical sub, then in 5.21.7 the deparser started package-qualifying
shadowed subs. So the present behaviour seems to be a mistake, arising
from treating subs just like scalars in the relationship between package
and lexical namespaces. It was correct to look for lexical shadowing,
but undesirable to suppose that "use strict 'vars'" would apply to them.
Recently the deparsing of the affected case was accidentally
`fixed' to the short form (without reintroducing any shadowing bug)
by commit dd66616. However, this
broke a test in Devel::Cover's test suite. The test is sensitive to
non-guaranteed details of deparsing, and has a mechanism for updating
expectations when the deparsing changes, which had already been applied
to change the expectation in 5.22. Because breaking this test wasn't
intentional, the deparsing was changed back to the long form in commit 257296e to resolve the BBC. This ticket
is about *intentionally* fixing it.
To fix the deparsing, revert the code part of commit 257296e, and update the "\&foo" and
"exists(&foo)" tests added by that commit. The change will break
Devel::Cover, so best make sure pjcj is ready first.
Migrated from rt.perl.org#132461 (status was 'new')
Searchable as RT132461$
The text was updated successfully, but these errors were encountered: