Skip to content

Fix soundness in ? operator chains via Expr.DynamicChain node#3352

Merged
nojaf merged 2 commits intofsprojects:mainfrom
nojaf:fix-3159
Apr 16, 2026
Merged

Fix soundness in ? operator chains via Expr.DynamicChain node#3352
nojaf merged 2 commits intofsprojects:mainfrom
nojaf:fix-3159

Conversation

@nojaf
Copy link
Copy Markdown
Contributor

@nojaf nojaf commented Apr 16, 2026

Two or more chained ? accesses (e.g. x?a("")?b(t)) were formatted with
a space before each parenthesised argument when SpaceBefore*Invocation
was enabled. The space changed how the next ?member was parsed,
producing code that no longer matched the original AST.

Detect the chain pattern during AST→Oak transformation and represent
it as a new Expr.DynamicChain node. The printer emits the chain tight,
sidestepping the per-call space rule. Lone ? calls still go through
the existing Expr.Dynamic / Expr.AppSingleParenArg paths and
continue to honour SpaceBefore(Upper|Lower)caseInvocation.

Fixes #3159

nojaf added 2 commits April 16, 2026 11:28
  Two or more chained `?` accesses (e.g. `x?a("")?b(t)`) were formatted
  with
  a space before each parenthesised argument when SpaceBefore*Invocation
  was
  enabled. The space changed how the next `?member` was parsed,
  producing
  code that no longer matched the original AST.

  Detect the chain pattern during AST→Oak transformation and represent
  it
  as a new `Expr.DynamicChain` node. The printer emits the chain tight,
  sidestepping the per-call space rule. Lone `?` calls still go through
  the existing `Expr.Dynamic` / `Expr.AppSingleParenArg` paths and
  continue
  to honour `SpaceBefore(Upper|Lower)caseInvocation`.
@nojaf nojaf merged commit 3478a9e into fsprojects:main Apr 16, 2026
10 of 11 checks passed
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.

Space should not be added before parentheses following ? operator

1 participant