Skip to content

awk: make next and nextfile in a function called from a special rule fatal - #199

Open
VanshajPoonia wants to merge 2 commits into
uutils:mainfrom
VanshajPoonia:awk-next-in-begin-178
Open

VanshajPoonia wants to merge 2 commits into
uutils:mainfrom
VanshajPoonia:awk-next-in-begin-178

Conversation

@VanshajPoonia

Copy link
Copy Markdown
Contributor

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 a BEGIN' 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.

…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 Alonely0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

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.

awk: next in a function called from BEGIN panics

2 participants