Skip to content

Revert "open: only treat literal undef as special" #23318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: blead
Choose a base branch
from
Open

Conversation

ap
Copy link
Contributor

@ap ap commented May 23, 2025

This reverts commit 471c834 (i.e. #22465) but also adds a test which the reverted code would not pass and a perldelta item.

Checks based on the syntax tree of the call site fix #22385 for some number of common cases, but not all of them, at the cost of breaking the ability of APIs that wrap open to expose its anonymous file mode. A notable example of such an API is autodie.

The current PSC is unanimous in disliking language features conditional on the exact shape of the syntax tree, as they make the language more brittle. The reported issue is a problem, but this attempt to fix is not a good approach long-term, especially given how many edge cases it leaves unsolved.


  • This set of changes requires a perldelta entry, and it is included.

This reverts commit 471c834 but also
adds a test which the reverted code would not pass and a perldelta item.
@ap ap requested review from tonycoz and mauke May 23, 2025 05:32
@mauke
Copy link
Contributor

mauke commented May 23, 2025

at the cost of breaking the ability of APIs that wrap open to expose its anonymous file mode

That is not quite true. Wrappers indeed could not replicate the "literal undef only" behavior of open, but they could keep their old behavior of triggering anonymous file mode in more cases¹. So in edge cases autodie would have stayed compatible with previous versions of autodie, but not with CORE::open.


¹ Description of "old behavior" omitted because I don't think such a description is possible. Anonymous file mode has no semantics. :-( Better fixes very much welcome.

@ap
Copy link
Contributor Author

ap commented May 24, 2025

Description of "old behavior" omitted because I don't think such a description is possible. Anonymous file mode has no semantics. :-( Better fixes very much welcome.

Frankly I think the API surface is just misshapen. It’s a cute idea to say “an undefined filename means the file is anonymous” but it makes a crappy API. If we are going to provide this functionality through open itself then the signal should be a different value than undef, one which doesn’t have other meanings attached to it (e.g. a reference that is blessed into a special package just for this, or an empty string with a special magic flag returned by some kind of builtin::tempfile function).

Unfortunately that means changing API, and I don’t know how feasible that is nowadays, given that a lot of Perl code is not going to receive maintenance. (I suppose maybe we could feature-gate this with a negative feature, so that in future you get something saner under a recent use VERSION, and then for old code perl can just expose the exact same behavior it always has.)

FWIW I appreciate your attempt to fix the API as is. It’s just I don’t think costs and benefits add up with this approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

open unexpectedly creates temporary files with undefined variables sometimes
3 participants