Skip to content

Clarify CS0112 scope for C# 11 static interface members#53157

Open
Copilot wants to merge 13 commits intomainfrom
copilot/update-cs0112-error-message
Open

Clarify CS0112 scope for C# 11 static interface members#53157
Copilot wants to merge 13 commits intomainfrom
copilot/update-cs0112-error-message

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 15, 2026

CS0112 docs currently imply static can’t combine with abstract/virtual in all contexts. Since C# 11 allows static abstract and static virtual on specific interface members, the guidance needed scope clarification.

  • Scope correction

    • Updated the CS0112 lead sentence to explicitly limit the error to classes and structs.
  • Rule clarification

    • Revised explanatory text to state that override/virtual/abstract + static is invalid in class/struct member declarations.
  • C# 11 exception added

    • Added a direct note that interface methods, properties, events, and operators can use static abstract and static virtual.
  • Consistency cleanup

    • Normalized keyword formatting in the rule sentence to use inline code style consistently.
A static member 'function' in a class or struct cannot be marked as override, virtual, or abstract.

Any method declaration in a class or struct that uses the `override`, `virtual`, or `abstract` keyword cannot also use the `static` keyword.

Starting in C# 11, interface methods, properties, events, and operators can use `static abstract` or `static virtual`.

Internal previews

📄 File 🔗 Preview link
docs/csharp/misc/cs0112.md docs/csharp/misc/cs0112

Copilot AI linked an issue Apr 15, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Update CS0112 member modifier combinations help text Clarify CS0112 scope for C# 11 static interface members Apr 15, 2026
Copilot AI requested a review from BillWagner April 15, 2026 17:55
Comment thread docs/csharp/misc/cs0112.md Outdated
Copy link
Copy Markdown
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

@copilot Address my comment on L17 and this is ready.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 15, 2026

@copilot Address my comment on L17 and this is ready.

Addressed in commit fd9d4209. The CS0112 page now states the pre-C# 11 restriction and explicitly describes the C# 11 exception for static abstract and static virtual interface members. No UI changes were made (documentation-only update).

Copilot AI requested a review from BillWagner April 15, 2026 18:08
Comment thread docs/csharp/misc/cs0112.md Outdated
Copy link
Copy Markdown
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

This is ready for final review.

@BillWagner BillWagner marked this pull request as ready for review April 15, 2026 18:11
@BillWagner BillWagner requested a review from a team as a code owner April 15, 2026 18:11
Copilot AI review requested due to automatic review settings April 15, 2026 18:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Clarifies the scope of compiler error CS0112 so the guidance doesn’t conflict with C# 11’s support for static abstract and static virtual interface members.

Changes:

  • Updates the CS0112 lead sentence to scope the rule to class and struct members.
  • Revises the explanatory text to consistently format keywords and clarify invalid modifier combinations.
  • Adds a note calling out the C# 11 interface-member exception for static abstract/static virtual.

Comment thread docs/csharp/misc/cs0112.md Outdated
@BillWagner BillWagner requested a review from adegeo April 15, 2026 18:19
@BillWagner BillWagner enabled auto-merge (squash) April 15, 2026 18:19
Copilot AI requested a review from BillWagner April 15, 2026 18:19
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.

CS0112 re member modifier combinations

3 participants