Skip to content

[dslx] Allow for/unroll_for expressions as operands in binary operations#4152

Open
anishesg wants to merge 1 commit intogoogle:mainfrom
anishesg:fix/ph-issue-3967
Open

[dslx] Allow for/unroll_for expressions as operands in binary operations#4152
anishesg wants to merge 1 commit intogoogle:mainfrom
anishesg:fix/ph-issue-3967

Conversation

@anishesg
Copy link
Copy Markdown

Fixes #3967

Parsing an inline for expression as the RHS of a binary operation (e.g., p ^ for (i, acc) in u32:0..u32:8 { ... }(u1:1)) produced a spurious parse error:

ParseError: Expected start of an expression; got: keyword:for

The DSLX parser's ParseTermLhs function handles several keyword-prefixed sub-expressions (if, const if, const for, const match, match) but was missing cases for plain for and unroll_for. When descending into ParseTermLhs to parse the RHS of a binary operator, encountering a for keyword hit the fallthrough error case.

The fix adds kFor/kUnrollFor handling to ParseTermLhs, consistent with how the same keywords are already handled in ParseExpression for top-level expressions.

  • Adds for and unroll_for keyword cases to ParseTermLhs to call ParseFor directly
  • Adds a regression test ForExpressionAsRhsOfBinop that round-trips p ^ for (...) in ... { ... }(...)

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 22, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@anishesg anishesg marked this pull request as ready for review April 23, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dslx parse error on expressions with inline for

2 participants