Skip to content

fix(compiler): include union type name in invalid-discriminated-union-variant diagnostic#10199

Merged
baywet merged 3 commits intomainfrom
copilot/fix-invalid-discriminated-union-variant
Mar 30, 2026
Merged

fix(compiler): include union type name in invalid-discriminated-union-variant diagnostic#10199
baywet merged 3 commits intomainfrom
copilot/fix-invalid-discriminated-union-variant

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 30, 2026

The duplicateDefaultVariant message for invalid-discriminated-union-variant was a static string with no context about which union triggered the error, making it hard to act on.

Changes

  • messages.ts: Convert duplicateDefaultVariant from a static string to a paramMessage template accepting a unionName parameter
  • discriminator-utils.ts: Pass format: { unionName: type.name ?? "(anonymous)" } to the diagnostic
  • decorators.test.ts: Update test assertion to match the new message format

Before / After

// Before
Discriminated union only allow a single default variant(Without a variant name).

// After
Discriminated union Foo only allow a single default variant(Without a variant name).

@microsoft-github-policy-service microsoft-github-policy-service Bot added the compiler:core Issues for @typespec/compiler label Mar 30, 2026
Copilot AI changed the title [WIP] Fix error message for invalid discriminated union variant fix(compiler): include union type name in invalid-discriminated-union-variant diagnostic Mar 30, 2026
Copilot AI requested a review from baywet March 30, 2026 14:17
@baywet baywet marked this pull request as ready for review March 30, 2026 14:28
@baywet baywet enabled auto-merge March 30, 2026 14:28
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 30, 2026

Open in StackBlitz

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

commit: 533997e

@azure-sdk
Copy link
Copy Markdown
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@baywet baywet added this pull request to the merge queue Mar 30, 2026
Merged via the queue into main with commit 9295341 Mar 30, 2026
40 checks passed
@baywet baywet deleted the copilot/fix-invalid-discriminated-union-variant branch March 30, 2026 16:39
msyyc pushed a commit that referenced this pull request Apr 1, 2026
…n-variant` diagnostic (#10199)

The `duplicateDefaultVariant` message for
`invalid-discriminated-union-variant` was a static string with no
context about which union triggered the error, making it hard to act on.

## Changes

- **`messages.ts`**: Convert `duplicateDefaultVariant` from a static
string to a `paramMessage` template accepting a `unionName` parameter
- **`discriminator-utils.ts`**: Pass `format: { unionName: type.name ??
"(anonymous)" }` to the diagnostic
- **`decorators.test.ts`**: Update test assertion to match the new
message format

### Before / After

```
// Before
Discriminated union only allow a single default variant(Without a variant name).

// After
Discriminated union Foo only allow a single default variant(Without a variant name).
```

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: baywet <[email protected]>
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.

error invalid-discriminated-union-variant should give you the union type name

4 participants