Skip to content

Fix formatter regression for union as named template argument#11093

Merged
iscai-msft merged 2 commits into
microsoft:mainfrom
timotheeguerin:named-template-arg-union-format
Jun 25, 2026
Merged

Fix formatter regression for union as named template argument#11093
iscai-msft merged 2 commits into
microsoft:mainfrom
timotheeguerin:named-template-arg-union-format

Conversation

@timotheeguerin

Copy link
Copy Markdown
Member

Fixes #11092

Problem

PR #11010 fixed a blank-line / over-indent issue when a union expression is used as one of several positional template arguments. That fix made printUnion suppress its own leading line + indent when the union is a direct argument of a multi-argument template reference (the surrounding argument list already supplies them).

This regressed the named template argument case (Name = <union>). For a named argument the union is printed after Name = , so the argument list's line break / indent does not apply to the union variants. Suppressing the union's own break + indent collapsed the variants:

alias Alias = Test<
  A = "Some long value",
  TakesALongUnion = | string
  | int32
  | int64
  | "Some very long string that split line"
>;

Fix

isInMultiTemplateArgumentList now returns false when the parent TemplateArgument has a name. Named-argument unions fall back to the standalone behavior (their own leading line + | + indent):

alias Alias = Test<
  A = "Some long value",
  TakesALongUnion =
    | string
    | int32
    | int64
    | "Some very long string that split line"
>;

The single-argument case and the positional multi-argument case (#11009) are unchanged.

Tests

@microsoft-github-policy-service microsoft-github-policy-service Bot added the compiler:core Issues for @typespec/compiler label Jun 25, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@11093

commit: 555ec97

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - internal ✏️

Fix formatter regression where a union used as a named template argument lost its leading | indentation

@azure-sdk-automation

azure-sdk-automation Bot commented Jun 25, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@timotheeguerin timotheeguerin marked this pull request as ready for review June 25, 2026 14:40
@iscai-msft iscai-msft added this pull request to the merge queue Jun 25, 2026
Merged via the queue into microsoft:main with commit 8596473 Jun 25, 2026
42 of 44 checks passed
@oha-4 oha-4 mentioned this pull request Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in formatting

2 participants