dotnet / dotnet/csharpstandard

Prohibiting Duplicate Modifiers

Open
#594 4 comments 0 reactions 1 assignee Claimed by @RexJaeschke View on GitHub
type: clarity
Dominant language
C#
Stars
815
Forks
99
Avg merge
1d 14h
Merged PRs (30d)
16

Description

While discussing PR #[215](https://github.com/dotnet/csharpstandard/pull/215), “private protected access modifier,” on the June 2022 TG2 call, @gafter mentioned that prose that disallows duplicate modifiers was missing in some contexts. And rather than adding it to those “missing” places, perhaps we could make a single, general statement re that instead.

The prohibition on having duplicate modifiers is handled in the following ways:
- In the grammar (e.g., [§14.12](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/classes.md#1412-static-constructors)), by allowing only specific individual modifiers or combinations thereof. As such, no prose is needed.
- Explicitly in prose (e.g., [§14.2.2.1](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/classes.md#14221-general)), by stating, “It is an error for the same modifier to appear multiple times in an *xxx* declaration.”
- Implicitly in prose (e.g., [§14.7.1](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/classes.md#1471-general)), by stating, “*yyy* declarations are subject to the same rules as method declarations with regard to valid combinations of modifiers.” **However, this assumes that “valid combinations” includes “no duplicates,” which might not be obvious/sufficient.**

**All grammar rules containing modifiers use one of the above approaches.**

Three rules (property/event/indexer declarations) use the “implicitly in prose” approach, so if that approach is deemed insufficient, we can add words to them. Otherwise, I don’t see any changes are needed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.