From 69f41a89342d78b33679dd22596cad660b7ff9c0 Mon Sep 17 00:00:00 2001 From: Olabamiji Oyetubo <60369677+bigboybamo@users.noreply.github.com> Date: Tue, 11 Jun 2024 23:36:22 +0100 Subject: [PATCH 1/4] Update access-modifiers.md Added description for file access type modifier --- .../programming-guide/classes-and-structs/access-modifiers.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/csharp/programming-guide/classes-and-structs/access-modifiers.md b/docs/csharp/programming-guide/classes-and-structs/access-modifiers.md index 5543714e1a752..2fc42d93fb2ac 100644 --- a/docs/csharp/programming-guide/classes-and-structs/access-modifiers.md +++ b/docs/csharp/programming-guide/classes-and-structs/access-modifiers.md @@ -73,6 +73,8 @@ To set the access level for a `class` or `struct` member, add the appropriate ke Finalizers can't have accessibility modifiers. Members of an `enum` type are always `public`, and no access modifiers can be applied. +The `file` access modifier is allowed only on top-level (non-nested) type declarations. + ## C# language specification [!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)] From 6545411dce22f44f1bea98796dea60f9bad48303 Mon Sep 17 00:00:00 2001 From: Olabamiji Oyetubo <60369677+bigboybamo@users.noreply.github.com> Date: Thu, 31 Jul 2025 20:31:07 +0100 Subject: [PATCH 2/4] Update constructor-errors.md --- .../compiler-messages/constructor-errors.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/csharp/language-reference/compiler-messages/constructor-errors.md b/docs/csharp/language-reference/compiler-messages/constructor-errors.md index 15747bd50e2fd..aec85a2bc8364 100644 --- a/docs/csharp/language-reference/compiler-messages/constructor-errors.md +++ b/docs/csharp/language-reference/compiler-messages/constructor-errors.md @@ -110,7 +110,7 @@ That's by design. The text closely matches the text of the compiler error / warn - [**CS8054**](#constructor-declaration): *Enums cannot contain explicit parameterless constructors.* - [**CS8091**](#constructor-declaration): *cannot be extern and have a constructor initializer.* - [**CS8861**](#primary-constructor-declaration): *Unexpected argument list.* -- [**CS8862**](#primary-constructor-declaration): *A constructor declared in a type with parameter list must have 'this' constructor initializer.* +- [**CS8862**](#primary-constructor-declaration): *Every declared constructor must call `this(...)` where the `...` argument list invokes the primary constructor.* - [**CS8358**](#constructor-declaration): *Cannot use attribute constructor because it has 'in' parameters.* - [**CS8867**](#records-and-copy-constructors): *No accessible copy constructor found in base type '{0}'.* - [**CS8868**](#records-and-copy-constructors): *A copy constructor in a record must call a copy constructor of the base, or a parameterless object constructor if the record inherits from object.* @@ -237,7 +237,7 @@ Adding the `record` modifier to a `struct` or `class` type creates a [record](.. The compiler emits the following errors when a primary constructor violates one or more rules on primary constructors for classes and structs: - **CS8861**: *Unexpected argument list.* -- **CS8862**: *A constructor declared in a type with parameter list must have 'this' constructor initializer.* +- **CS8862**: *Every declared constructor must call `this(...)` where the `...` argument list invokes the primary constructor.* - **CS9105**: *Cannot use primary constructor parameter in this context.* - **CS9106**: *Identifier is ambiguous between type and parameter in this context.* - **CS9108**: *Cannot use parameter that has ref-like type inside an anonymous method, lambda expression, query expression, or local function.* From b278beb86ebb21774b2acbf407d0f7831472a952 Mon Sep 17 00:00:00 2001 From: Olabamiji Oyetubo <60369677+bigboybamo@users.noreply.github.com> Date: Thu, 31 Jul 2025 21:18:11 +0100 Subject: [PATCH 3/4] Update constructor-errors.md --- .../compiler-messages/constructor-errors.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/csharp/language-reference/compiler-messages/constructor-errors.md b/docs/csharp/language-reference/compiler-messages/constructor-errors.md index aec85a2bc8364..2572c7321b141 100644 --- a/docs/csharp/language-reference/compiler-messages/constructor-errors.md +++ b/docs/csharp/language-reference/compiler-messages/constructor-errors.md @@ -110,7 +110,7 @@ That's by design. The text closely matches the text of the compiler error / warn - [**CS8054**](#constructor-declaration): *Enums cannot contain explicit parameterless constructors.* - [**CS8091**](#constructor-declaration): *cannot be extern and have a constructor initializer.* - [**CS8861**](#primary-constructor-declaration): *Unexpected argument list.* -- [**CS8862**](#primary-constructor-declaration): *Every declared constructor must call `this(...)` where the `...` argument list invokes the primary constructor.* +- [**CS8862**](#primary-constructor-declaration): *A constructor declared in a type with parameter list must have 'this' constructor initializer.* - [**CS8358**](#constructor-declaration): *Cannot use attribute constructor because it has 'in' parameters.* - [**CS8867**](#records-and-copy-constructors): *No accessible copy constructor found in base type '{0}'.* - [**CS8868**](#records-and-copy-constructors): *A copy constructor in a record must call a copy constructor of the base, or a parameterless object constructor if the record inherits from object.* @@ -237,7 +237,7 @@ Adding the `record` modifier to a `struct` or `class` type creates a [record](.. The compiler emits the following errors when a primary constructor violates one or more rules on primary constructors for classes and structs: - **CS8861**: *Unexpected argument list.* -- **CS8862**: *Every declared constructor must call `this(...)` where the `...` argument list invokes the primary constructor.* +- **CS8862**: *A constructor declared in a type with parameter list must have 'this' constructor initializer.* - **CS9105**: *Cannot use primary constructor parameter in this context.* - **CS9106**: *Identifier is ambiguous between type and parameter in this context.* - **CS9108**: *Cannot use parameter that has ref-like type inside an anonymous method, lambda expression, query expression, or local function.* @@ -257,6 +257,8 @@ The compiler emits the following errors when a primary constructor violates one - **CS9124**: *Parameter is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.* - **CS9136**: *Cannot use primary constructor parameter of type inside an instance member.* +When using a primary constructor in a class or struct, every explicitly declared constructor must call the primary constructor using `: this(...)` with an appropriate argument list. This ensures that the primary constructor is always invoked. See [programming guide](../../programming-guide/classes-and-structs/instance-constructors.md#primary-constructors) for more details. + Primary constructor parameters are in scope in the body of that type. The compiler can synthesize a field that stores the parameter for use in members or in field initializers. Because a primary constructor parameter may be copied to a field, the following restrictions apply: - Primary constructors can be declared on `struct` and `class` types, but not on `interface` types. From 30e39abc01e6b484bebecca6666d0842c85fda04 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Thu, 31 Jul 2025 16:51:00 -0400 Subject: [PATCH 4/4] Update docs/csharp/language-reference/compiler-messages/constructor-errors.md --- .../language-reference/compiler-messages/constructor-errors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/compiler-messages/constructor-errors.md b/docs/csharp/language-reference/compiler-messages/constructor-errors.md index 2572c7321b141..83fddeb272192 100644 --- a/docs/csharp/language-reference/compiler-messages/constructor-errors.md +++ b/docs/csharp/language-reference/compiler-messages/constructor-errors.md @@ -257,7 +257,7 @@ The compiler emits the following errors when a primary constructor violates one - **CS9124**: *Parameter is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.* - **CS9136**: *Cannot use primary constructor parameter of type inside an instance member.* -When using a primary constructor in a class or struct, every explicitly declared constructor must call the primary constructor using `: this(...)` with an appropriate argument list. This ensures that the primary constructor is always invoked. See [programming guide](../../programming-guide/classes-and-structs/instance-constructors.md#primary-constructors) for more details. +When using a primary constructor in a class or struct, every explicitly declared constructor must call the primary constructor using `: this(...)` with an appropriate argument list. This ensures that the primary constructor is always invoked. For more information on primary constructors, see the article on [instance constructors](../../programming-guide/classes-and-structs/instance-constructors.md#primary-constructors) in the programming guide. Primary constructor parameters are in scope in the body of that type. The compiler can synthesize a field that stores the parameter for use in members or in field initializers. Because a primary constructor parameter may be copied to a field, the following restrictions apply: