Skip to content

Support extension members in API diff - #55356

Merged
jeffhandley merged 7 commits into
dotnet:mainfrom
jeffhandley:apidiff-extension-members
Jul 19, 2026
Merged

jeffhandley merged 7 commits into
dotnet:mainfrom
jeffhandley:apidiff-extension-members

Conversation

@jeffhandley

@jeffhandley jeffhandley commented Jul 19, 2026 •

Copy link
Copy Markdown
Member

Preserves C# extension blocks in API diffs, suppresses compiler-generated implementation methods, and adds extension-member test coverage.

Original context: API diff between .NET 11 Preview 5 and .NET 11 Preview 6 (dotnet/core#10485)

Copilot AI review requested due to automatic review settings July 19, 2026 03:37
@jeffhandley
jeffhandley requested a review from a team as a code owner July 19, 2026 03:37
@azure-pipelines

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

- Multiple extension blocks for different, same, and alternating target types
- Generic static extension members
- Constrained and unconstrained generic instance and static members at block and member levels

Co-authored-by: Copilot App <[email protected]>
Copilot AI review requested due to automatic review settings July 19, 2026 04:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates the API diff pipeline to preserve C# extension(...) { ... } blocks in generated API baselines/diffs, while suppressing the compiler-generated “implementation” methods that would otherwise show up as ordinary members on the containing type. It also adds dedicated test coverage to validate the resulting diff output for extension members (methods/properties, generic/constrained cases, multiple blocks/receiver types).

Changes:

  • Add MSTest coverage for extension-member additions/changes/deletions and multi-block scenarios.
  • Update GenAPI C# document generation to filter out extension-block implementation methods when emitting members.
  • Update the in-memory diff generator to normalize extension-block receiver formatting and treat extension blocks as public/protected-visible members for diff purposes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test/Microsoft.DotNet.ApiDiff.Tests/Diff.ExtensionMember.Tests.cs Adds API diff tests covering extension blocks and extension members across multiple shapes (static/instance, generic, constrained, multi-block).
src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/CSharpAssemblyDocumentGenerator.cs Filters named-type members to suppress compiler-generated implementation methods for extension members while preserving extension blocks.
src/Compatibility/ApiDiff/Microsoft.DotNet.ApiDiff/MemoryOutputDiffGenerator.cs Normalizes unnamed receiver formatting in extension blocks and ensures extension blocks participate in member visibility selection for diffs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/CSharpAssemblyDocumentGenerator.cs:326

  • IsMatchingExtensionMethod can return true for unrelated overloads because it never validates the receiver parameter type. For example, an ordinary method M(string) could be incorrectly treated as the compiler-generated implementation for an instance extension member M() on extension(int ...), since the current check only compares name/arity/return type and then zips non-receiver parameters (which are empty). Adding a receiver-type check (derived from the extension block’s receiver constructor parameter) makes the filter safe.
        int receiverParameterCount = extensionMethod.IsStatic ? 0 : 1;
        if (implementation.Name != extensionMethod.Name ||
            implementation.Arity != extensionBlock.Arity + extensionMethod.Arity ||
            implementation.Parameters.Length != extensionMethod.Parameters.Length + receiverParameterCount ||
            !HasMatchingType(implementation.ReturnType, extensionMethod.ReturnType))

jeffhandley and others added 2 commits July 18, 2026 21:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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

@jeffhandley
jeffhandley enabled auto-merge (squash) July 19, 2026 06:26
@jeffhandley
jeffhandley merged commit 7e0c7c9 into dotnet:main Jul 19, 2026
43 checks passed
@jeffhandley
jeffhandley deleted the apidiff-extension-members branch July 19, 2026 08:21
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants