Skip to content

Port #62311: Fix parenthesizer rules for binary expressions mixing ?? with ||/&&#2758

Merged
DanielRosenwasser merged 3 commits intomainfrom
copilot/fix-parenthesizer-rules
Feb 11, 2026
Merged

Port #62311: Fix parenthesizer rules for binary expressions mixing ?? with ||/&&#2758
DanielRosenwasser merged 3 commits intomainfrom
copilot/fix-parenthesizer-rules

Conversation

Copy link
Contributor

Copilot AI commented Feb 11, 2026

  • Port TypeScript PR #62311: Fix parenthesizer rules for manually constructed binary expressions with ?? and ||/&& mix
  • Add mixingBinaryOperatorsRequiresParentheses helper function in the printer utilities
  • Modify emitBinaryExpression to check for operator mixing before emitting left/right operands
  • Fix regression: only apply mixing check for synthesized (factory-created) nodes, not parsed source code
  • Add comprehensive unit tests for all operator mixing combinations
  • Build and verify changes compile
  • Run full test suite - all tests pass with no regressions
  • Run code review and security checks

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…ith ?? and ||/&& mix

Port of microsoft/TypeScript#62311

When emitting binary expressions, the printer now checks if the parent
operator and child operator are a mix of ?? with ||/&&, which requires
parentheses per JavaScript spec. This prevents emitting syntactically
invalid code like `a || b ?? c` and instead correctly emits `(a || b) ?? c`.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix parenthesizer rules for binary expressions with ?? and ||/&& mix Port #62311: Fix parenthesizer rules for binary expressions mixing ?? with ||/&& Feb 11, 2026
Copilot AI requested a review from jakebailey February 11, 2026 06:44
The parenthesization for ?? and ||/&& mixing should only apply to
manually constructed (synthesized) AST nodes, not parsed source code.
Parsed code like `a || b ?? c` should be faithfully reproduced even
though it's a syntax error, matching TypeScript's behavior.

Added `ast.NodeIsSynthesized` check to guard the mixing parenthesization,
and added comprehensive unit tests for all mixing combinations.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@jakebailey
Copy link
Member

@jakebailey jakebailey marked this pull request as ready for review February 11, 2026 16:31
Copilot AI review requested due to automatic review settings February 11, 2026 16:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Ports TypeScript PR #62311 to the Go printer to ensure emitted output is syntactically valid when synthesized (factory-created) binary expressions mix ?? with ||/&&, while preserving parsed source output.

Changes:

  • Added mixingBinaryOperatorsRequiresParentheses helper to detect ?? mixing with ||/&&.
  • Updated emitBinaryExpression to force parentheses around synthesized left/right operands when such operator mixing occurs.
  • Added a table-driven printer test covering synthesized AST cases for all ?? + ||/&& mixing combinations and operand sides.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
internal/printer/utilities.go Adds helper for detecting ?? mixed with `
internal/printer/printer.go Applies mixing rule during binary expression emit for synthesized operands by forcing higher precedence (parenthesization).
internal/printer/printer_test.go Adds table-driven test validating emitted parentheses for synthesized mixed-operator binary expressions.

@DanielRosenwasser DanielRosenwasser added this pull request to the merge queue Feb 11, 2026
Merged via the queue into main with commit 6b6926f Feb 11, 2026
26 checks passed
@DanielRosenwasser DanielRosenwasser deleted the copilot/fix-parenthesizer-rules branch February 11, 2026 19:30
Copilot AI added a commit that referenced this pull request Feb 25, 2026
… with ||/&& (#2758)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
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.

4 participants