Skip to content

Accept the in operator in a compiled expression - #686

Open
bertysentry wants to merge 1 commit into
mainfrom
claude/issue-685-caihgf
Open

bertysentry wants to merge 1 commit into
mainfrom
claude/issue-685-caihgf

Conversation

@bertysentry

Copy link
Copy Markdown
Contributor

Fixes #685.

Problem

Awk.compileExpression() and Awk.eval() refused the in operator everywhere in an expression, also inside parentheses: $1 in arr, ("a" in arr) ? 1 : 0, !("PATH" in ENVIRON) and (1, 2) in arr all failed with a ParserException, while a program accepts them.

Fix

AwkParser.EXPRESSION_TO_EVALUATE() parsed the expression with allowInKeyword set to false. That flag is only meant for the first expression of a for (...) statement, so that for (key in arr) is left to the for production. An expression to evaluate has no such ambiguity, so it is now parsed with allowInKeyword set to true. That is the whole change in src/main.

Tests

  • AwkEvalTest: key in arr and (key in arr) on an array passed in the variables, inside a larger expression (ternary, arithmetic, concatenation, &&, ||), negated, the multi-dimensional form (i, j) in arr, on an ENVIRON passed by the host (regular and sandboxed), on an array never assigned, without optimization, and a check that in does not create the element. (1, 2) without in, "a" in and in arr are still refused.
  • AwkTest: in on the ENVIRON of the process, and on the empty ENVIRON of a SandboxedAwk.
  • AwkExpressionTest: an in expression is not reported as constant.

Documentation

  • New "Test Whether a Key Is in an Array" section in java-compile.md.
  • Bullet under Unreleased in behavior-changes.md.

Notes

  • Not changed: an assignment at the top level of an expression (x = 1) is still refused, as noted in the "Related" section of the issue. It comes from the same entry point but may be intended, so it is left for a separate decision.
  • mvn clean verify site passes: 1029 unit tests (1019 before), 0 Checkstyle, PMD and SpotBugs issues. The gawk compatibility tests report the same 129 failing tests with and without this change in my environment (they are not blocking, testFailureIgnore).

Generated by Claude Code

`Awk.compileExpression()` and `Awk.eval()` parsed the expression with
`allowInKeyword` set to false, so `$1 in arr`, `("a" in arr) ? 1 : 0`
and `(i, j) in arr` failed with a ParserException, also inside
parentheses. That flag is only meant for the first expression of a
`for (...)` statement, and an expression to evaluate has no such
ambiguity.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012oN698ZmgRVZHEQxfFpf9h
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T10:04:54.100840Z 3b55a4f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

This branch has not been deployed

No deployments
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.

The in operator is refused in a compiled expression

2 participants