Skip to content

Print parenthesis around intersections in unions #1240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Andarist
Copy link
Contributor

No description provided.

@Copilot Copilot AI review requested due to automatic review settings June 19, 2025 20:32
Copy link
Contributor

@Copilot 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

This PR adds explicit parentheses around intersections appearing in union types to improve the clarity and correctness of type printing. The changes span many baseline files where type output formatting is updated, and they include a modification in the printer logic to use a different precedence constant for union type constituents.

  • Updates printed representations of union types by wrapping intersection parts in parentheses.
  • Adjusts the internal printer’s handling of union constituents to ensure proper precedence.
  • Harmonizes formatting across multiple baseline test files.

Reviewed Changes

Copilot reviewed 81 out of 81 changed files in this pull request and generated no comments.

Show a summary per file
File Description
testdata/baselines/reference/submodule/conformance/unknownControlFlow.types.diff Adds parentheses in type outputs for unions with intersections.
testdata/baselines/reference/submodule/conformance/unionTypeInference.types.diff Updates union type printing to wrap intersections in parentheses.
testdata/baselines/reference/submodule/conformance/templateLiteralTypesPatterns.types.diff Adjusts parentheses for intersections in template literal types within unions.
testdata/baselines/reference/submodule/compiler/voidUndefinedReduction.types.diff Reformats printed union types to include parenthesis where needed.
internal/printer/printer.go Changes the precedence passed to type node emitter in union type constituents to enforce parenthesis.
Comments suppressed due to low confidence (1)

internal/printer/printer.go:1967

  • Verify that switching the precedence from ast.TypePrecedenceIntersection to ast.TypePrecedenceTypeOperator correctly prints union type constituents with the intended parenthesis without affecting non-union contexts. Consider adding tests to ensure that the change preserves the intended type precedence semantics.
	p.emitTypeNode(node, ast.TypePrecedenceTypeOperator)

@jakebailey jakebailey enabled auto-merge June 19, 2025 20:39
@jakebailey jakebailey added this pull request to the merge queue Jun 19, 2025
Merged via the queue into microsoft:main with commit 9fb6cec Jun 19, 2025
22 checks passed
@Andarist Andarist deleted the parens-around-intersections-in-unions branch June 19, 2025 21:08
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.

2 participants