Skip to content

Check custom code when preserving enum member underscores for backcompat - #11315

Merged
jorgerangel-msft merged 6 commits into
mainfrom
copilot/check-custom-code-preserve-enum-underscores
Jul 20, 2026
Merged

Check custom code when preserving enum member underscores for backcompat#11315
jorgerangel-msft merged 6 commits into
mainfrom
copilot/check-custom-code-preserve-enum-underscores

Conversation

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

The underscore back-compat pass restores previously-shipped underscore names (e.g. Tls1_0) when the current spec normalizes them (e.g. Tls10). For extensible enums whose custom code re-adds the underscore member, the restoration renamed the generated member back to the underscore form — colliding with the custom member and removing the generated symbol it referenced.

Example custom code that broke:

public partial struct ServiceBusMinimumTlsVersion
{
    // references the generated `Tls10`; back-compat renamed it to `Tls1_0`,
    // producing a duplicate and dropping `Tls10`
    public static ServiceBusMinimumTlsVersion Tls1_0 { get; } = Tls10;
}

Changes

  • EnumProvider.GetBackCompatibleName: new optional customMemberNames argument; skips the underscore restoration when the restored name already exists in custom code, keeping the generated name.
  • ExtensibleEnumProvider.BuildEnumValues: collects custom member names from CustomCodeView.Properties (case-insensitive) and threads them through. Uses CustomCodeView rather than CanonicalView to avoid the CanonicalView → Properties → EnumValues → BuildEnumValues recursion cycle; it contributes the same custom members.
  • Tests: adds BackCompat_ExtensibleEnumCustomCodeTakesPrecedenceOverPreservedUnderscores with (Custom)/(Last) TestData; existing BackCompat_ExtensibleEnumUnderscoresPreserved remains as the no-custom-code case.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Jul 20, 2026
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix enum member underscore preservation in custom code Check custom code when preserving enum member underscores for backcompat Jul 20, 2026
Copilot AI requested a review from jorgerangel-msft July 20, 2026 18:29
…a testdata

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@pkg-pr-new

pkg-pr-new Bot commented Jul 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@11315

commit: 0f7dcfd

…tract

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot AI requested a review from jorgerangel-msft July 20, 2026 19:55
@jorgerangel-msft
jorgerangel-msft marked this pull request as ready for review July 20, 2026 20:48
@jorgerangel-msft
jorgerangel-msft requested a review from m-nash as a code owner July 20, 2026 20:48
@jorgerangel-msft
jorgerangel-msft added this pull request to the merge queue Jul 20, 2026
Merged via the queue into main with commit 5510565 Jul 20, 2026
29 checks passed
@jorgerangel-msft
jorgerangel-msft deleted the copilot/check-custom-code-preserve-enum-underscores branch July 20, 2026 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check Custom Code When Preserve enum member underscores for backcompat

3 participants