Repository navigation
awk: make next and nextfile in a function called from a special rule fatal - #199
Open
VanshajPoonia wants to merge 2 commits into
Open
VanshajPoonia wants to merge 2 commits into
VanshajPoonia wants to merge 2 commits into
Conversation
…fatal A function called from BEGIN, END, BEGINFILE or ENDFILE could run next or nextfile and reach an unreachable!(). It now exits with 2 and a gawk-style message naming the rule.
Alonely0
reviewed
Nov 25, 2026
Alonely0
left a comment
Collaborator
There was a problem hiding this comment.
Notice this is not a runtime issue, but a parser one. gawk already fails for gawk 'BEGIN { if (0) next; }'. We already do this in the parser for some contextual keywords like continue, so perhaps you could replicate it for next and nextfile?
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.
Fixes #178.
next or nextfile directly in BEGIN, END, BEGINFILE or ENDFILE is rejected by the parser. Inside a function called from one of them it reached an unreachable!() in src/event.rs and panicked. The four event loops now return an error that names the rule. awk prints fatal:
next' cannot be called from aBEGIN' rule and exits 2 like gawk.nextfile in BEGINFILE is still allowed since it skips the file. That is what gawk does.
Tests: next_and_nextfile_from_a_function_in_a_special_rule_are_fatal fails on main. Two guards pass on both: nextfile in BEGINFILE skips the file and next in a normal rule skips the record.
gawk also prints the file and line before fatal. We print only fatal: because the signal carries no span. Adding one would mean changing Signal::Terminal so I left it out.