op.c: don't warn on 'open my $fh, $file;'#24378
Open
mauke wants to merge 2 commits intoPerl:bleadfrom
Open
Conversation
tonycoz
reviewed
Apr 21, 2026
Contributor
|
Should socket(), accept() be similarly excluded? I couldn't think of any others and I didn't find any more after a quick look through |
We have a hacky heuristic that complains about `Missing parentheses around "my" list` when it sees `my $x, $y;` or similar, assuming the programmer intended to declare both variables as local: `my ($x, $y);`. However, this warning is inappropriate for open/opendir because `open my $fh, $mode, $file` or `opendir my $dh, $dir` can appear in perfectly correct code. Detecting this case is not easy because the warning is generated by inspecting and the tokenizer state and manually reparsing parts of the input. This commit adds even more hackery and reparsing to avoid the inappropriate warning. Fixes Perl#4186.
These functions autovivify filehandles, just like open and opendir.
Contributor
Author
|
Makes sense. I've added |
tonycoz
approved these changes
Apr 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We have a hacky heuristic that complains about
Missing parentheses around "my" listwhen it seesmy $x, $y;or similar, assuming the programmer intended to declare both variables as local:my ($x, $y);.However, this warning is inappropriate for open/opendir because
open my $fh, $mode, $fileoropendir my $dh, $dircan appear in perfectly correct code. Detecting this case is not easy because the warning is generated by inspecting the tokenizer state and manually reparsing parts of the input. This commit adds even more hackery and reparsing to avoid the inappropriate warning.Fixes #4186.