Skip to content

Add support for custom overload names to CsWinMD#2275

Open
talagrand wants to merge 2 commits into
microsoft:masterfrom
talagrand:OverloadNames
Open

Add support for custom overload names to CsWinMD#2275
talagrand wants to merge 2 commits into
microsoft:masterfrom
talagrand:OverloadNames

Conversation

@talagrand

Copy link
Copy Markdown

This brings in support for OverloadAttribute to CsWinMD, so that the generated WinMD file carries that metadata.
Rust does not have support for overloaded methods, so windows-rs based consumers require this attribute to be set for API ergonomics.

@manodasanW

Copy link
Copy Markdown
Member

Thanks for this change and the tests, I have kicked off the CI.

@talagrand

Copy link
Copy Markdown
Author

There is a remaining issue with CsWinMD despite the tests passing. I need to push an addition to this change over the next couple days.

@Sergio0694

Copy link
Copy Markdown
Member

Ported to 3.0 in #2454. @manodasanW should we just abandon this one or do we still want it?

Sergio0694 added a commit that referenced this pull request Jul 24, 2026
* Honor author-specified [Overload] names in the WinMD generator

Port custom overload name support from PR #2275 (CsWinRT 2.x) to the
CsWinRT 3.0 WinMD generator (cswinrtwinmdgen). When an authored method
carries [Windows.Foundation.Metadata.Overload("Name")], emit that name in
the generated .winmd instead of an auto-generated sequential one. windows-rs
consumers require explicit overload names because Rust has no method overloading.

- Record author-specified overload names while emitting interface methods and
  honor them in AddOverloadAttributesForType; stop copying the [Overload]
  attribute verbatim so it is never duplicated.
- Select the default overload (which keeps the original name) from the
  [DefaultOverload] attribute rather than metadata order, so an author-specified
  name is not dropped when the default is not declared first.
- Auto-generated names skip any name already used by another method or an
  author-specified overload, avoiding collisions.
- Emit [Overload] only on interfaces (authored and synthesized), matching the
  Windows Runtime metadata convention; runtime classes expose their ABI through
  interfaces (consistent with CsWinRT 2.x).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Port custom overload name tests from PR #2275

Add the ICustomOverloadNames interface and CustomOverloadNamesClass authoring
types, and the CustomOverloadNames consumption test. The test validates that
author-specified [Overload] names (LookupByIndex, LookupByFlag, TransformNumber)
appear in the generated projection's ABI vtables, on both an authored interface
and a class's synthesized interface.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Add overload-name coverage for auto-generation, collisions, and default selection

Extend the overload-name tests to cover behaviors beyond the original PR:

- Verify the auto-generated ABI name (Transform2) coexists with an author-
  specified one (TransformNumber) in the same overload group.
- OverloadCollisionClass: an author-specified overload name matching the auto
  pattern ("M2") forces the auto-generated name of the remaining overload to
  skip it ("M3").
- DefaultOverloadNotFirstClass / IDefaultOverloadNotFirst: [DefaultOverload] on
  a non-first overload keeps the original ABI name, while the author-specified
  name ("GetByIndex") on the first overload is still honored.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@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.

3 participants