Skip to content

Commit cfa07ca

Browse files
committed
Add C# 14 error message before extensions
1 parent 21029e2 commit cfa07ca

File tree

4 files changed

+69
-14
lines changed

4 files changed

+69
-14
lines changed

docs/csharp/language-reference/compiler-messages/partial-declarations.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ f1_keywords:
4949
- "CS9263"
5050
- "CS9264"
5151
- "CS9266"
52+
- "CS9273"
53+
- "CS9275"
54+
- "CS9276"
55+
- "CS9277"
56+
- "CS9278"
57+
- "CS9279"
58+
- "CS9280"
5259
helpviewer_keywords:
5360
- "CS0260"
5461
- "CS0261"
@@ -96,7 +103,14 @@ helpviewer_keywords:
96103
- "CS9258"
97104
- "CS9263"
98105
- "CS9266"
99-
ms.date: 11/06/2024
106+
- "CS9273"
107+
- "CS9275"
108+
- "CS9276"
109+
- "CS9277"
110+
- "CS9278"
111+
- "CS9279"
112+
- "CS9280"
113+
ms.date: 05/23/2025
100114
---
101115
# Errors and warnings related to `partial` type and `partial` member declarations
102116

@@ -150,11 +164,18 @@ That's by design. The text closely matches the text of the compiler error / warn
150164
- [**CS9257**](#partial-properties): *Both partial property declarations must be required or neither may be required*
151165
- [**CS9258**](#field-backed-properties): *In this language version, the '`field`' keyword binds to a synthesized backing field for the property. To avoid generating a synthesized backing field, and to refer to the existing member, use '`this.field`' or '`@field`' instead.*
152166
- [**CS9263**](#field-backed-properties): *A partial property cannot have an initializer on both the definition and implementation.*
167+
- [**CS9275**](#partial-members): *Partial member must have an implementation part.*
168+
- [**CS9276**](#partial-members): *Partial member must have a definition part.*
169+
- [**CS9277**](#partial-members): *Partial member may not have multiple defining declarations.*
170+
- [**CS9278**](#partial-members): *Partial member may not have multiple implementing declarations.*
171+
- [**CS9279**](#partial-events-and-constructors): *Partial event cannot have initializer.*
172+
- [**CS9280**](#partial-events-and-constructors): *Only the implementing declaration of a partial constructor can have an initializer.*
153173

154174
The following warnings can be generated for field backed properties:
155175

156176
- [**CS9264**](#field-backed-properties): *Non-nullable property must contain a non-null value when exiting constructor. Consider adding the 'required' modifier, or declaring the property as nullable, or adding '`[field: MaybeNull, AllowNull]`' attributes.**
157177
- [**CS9266**](#field-backed-properties): *One accessor of property should use '`field`' because the other accessor is using it.*
178+
- [**CS9273**](#field-backed-properties): *In this language version, '`field`' is a keyword within a property accessor. Rename the variable or use the identifier '`@field`' instead.*
158179

159180
The following sections explain the cause and fixes for these errors and warnings.
160181

@@ -202,8 +223,12 @@ The compiler warns you if you have multiple fields declared in multiple files fo
202223
- **CS8800**: *Both partial member declarations must have identical combinations of `virtual`, `override`, `sealed`, and `new` modifiers.*
203224
- **CS8818**: *Partial member declarations must have matching `ref` return values.*
204225
- **CS8988**: *The `scoped` modifier of parameter doesn't match partial definition.*
226+
- **CS9275**: *Partial member must have an implementation part.*
227+
- **CS9276**: *Partial member must have a definition part.*
228+
- **CS9277**: *Partial member may not have multiple defining declarations.*
229+
- **CS9278**: *Partial member may not have multiple implementing declarations.*
205230

206-
Partial members have two declarations. The declaration without an implementation is the *declaring declaration*. The declaration with the implementation is the *implementing declaration*. Partial members are allowed only in a `partial` type. Partial members can't be `abstract`. Partial members can't explicitly implement an interface. Both declarations of a partial member must have identical signatures. For example, either both or neither declarations can include the `static` or `unsafe` modifiers.
231+
Partial members must have two declarations. The declaration without an implementation is the *defining declaration*. The declaration with the implementation is the *implementing declaration*. Both declarations are required. Partial members are allowed only in a `partial` type. Partial members can't be `abstract`. Partial members can't explicitly implement an interface. Both declarations of a partial member must have identical signatures. For example, either both or neither declarations can include the `static` or `unsafe` modifiers.
207232

208233
## Partial methods
209234

@@ -249,15 +274,23 @@ A partial property or indexer must have both a *declaring declaration* and an *i
249274
public partial int ImplementingDeclaration { get => field; set; }
250275
```
251276

277+
## Partial events and constructors
278+
279+
- **CS9279**: *Partial event cannot have initializer.*
280+
- **CS9280**: *Only the implementing declaration of a partial constructor can have an initializer.*
281+
282+
You've declared an initializer on the defining declaration of a partial constructor or on a partial event declaration. You must remove it.
283+
252284
## field backed properties
253285

254286
- **CS9258**: *In this language version, the '`field`' keyword binds to a synthesized backing field for the property. To avoid generating a synthesized backing field, and to refer to the existing member, use '`this.field`' or '`@field`' instead.*
255287
- **CS9263**: *A partial property cannot have an initializer on both the definition and implementation.*
256288
- **CS9264**: *Non-nullable property must contain a non-null value when exiting constructor. Consider adding the 'required' modifier, or declaring the property as nullable, or adding '`[field: MaybeNull, AllowNull]`' attributes.**
257289
- **CS9266**: *One accessor of property should use '`field`' because the other accessor is using it.*
290+
- **CS9273**: *In this language version, '`field`' is a keyword within a property accessor. Rename the variable or use the identifier '`@field`' instead.*
258291

259292
[!INCLUDE[field-preview](../../includes/field-preview.md)]
260293

261-
Beginning with C# 13, the preview feature, `field` backed properties allows you to access the compiler synthesized backing field for a property. **CS9258** indicates that you have a variable named `field`, which can be hidden by the contextual keyword `field`.
294+
Beginning with C# 13, the preview feature, `field` backed properties allows you to access the compiler synthesized backing field for a property. **CS9258** or **CS9273** indicate that you have a variable named `field`, which can be hidden by the contextual keyword `field`.
262295

263296
**CS9263** indicates that your declaring declaration includes an implementation. That implementation might be accessing the compiler synthesized backing field for that property. **CS9264** indicates that the your use of `field` assumes a non-nullable backing field while the property declaration is nullable. The compiler assumes both the backing field and the property have the same nullability. You need to add the `[field:MaybeNull, AllowNull]` attribute to the property declaration to indicate that the `field` value should be considered nullable. **CS9266** indicates that one of a properties accessors uses the `field` keyword, but the other uses a hand-declared backing field. The warning indicates you may have done that by accident.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Errors and warnings for string literal declarations
3+
description: This article helps you diagnose and correct compiler errors and warnings when you declare string literals as constants or variables.
4+
f1_keywords:
5+
- "CS9274"
6+
helpviewer_keywords:
7+
- "CS9274"
8+
ms.date: 05/23/2025
9+
---
10+
# Errors and warnings for string literal declarations
11+
12+
There are a few *errors* related to declaring string constants or string literals.
13+
14+
<!-- The text in this list generates issues for Acrolinx, because they don't use contractions.
15+
That's by design. The text closely matches the text of the compiler error / warning for SEO purposes.
16+
-->
17+
- [**CS9274**](#constant-declarations): *Cannot emit this string literal into the data section because it has XXHash128 collision with another string literal.*
18+
19+
## Constant declarations
20+
21+
- [**CS9274**](#constant-declarations): *Cannot emit this string literal into the data section because it has XXHash128 collision with another string literal.*
22+
23+
These errors indicate that your declaration can't be emitted in the data section. Turn this feature off for your application.

docs/csharp/language-reference/toc.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ items:
466466
CS0171, CS0188, CS0843, CS8904, CS1738, CS8022, CS8023, CS8024, CS8025, CS8026, CS8058, CS8059, CS8107, CS8192, CS8302,
467467
CS8303, CS8304, CS8305, CS8306, CS8314, CS8320, CS8370, CS8371, CS8400, CS8401, CS8511, CS8627, CS8630, CS8652, CS8703,
468468
CS8704, CS8706, CS8773, CS8912, CS8919, CS8929, CS8936, CS8957, CS8967, CS9014, CS9015, CS9016, CS9017, CS9058, CS9064,
469-
CS9103, CS9171, CS9194, CS9202, CS9204, CS9240, CS9260, CS9268, CS9269
469+
CS9103, CS9171, CS9194, CS9202, CS9204, CS9240, CS9260, CS9268, CS9269, CS9271
470470
- name: Assembly references
471471
href: ./compiler-messages/assembly-references.md
472472
displayName: >
@@ -503,18 +503,22 @@ items:
503503
displayName: >
504504
yield return, yield break,
505505
CS1622, CS1624, CS1625, CS1626, CS1627, CS1629, CS1631, CS1637, CS4013, CS8154, CS8176, CS9237, CS9238, CS9239
506+
- name: Extension declarations
507+
href: ./compiler-messages/extension-declarations.md
508+
displayName:
506509
- name: Partial declarations
507510
href: ./compiler-messages/partial-declarations.md
508511
displayName: >
509512
partial type, partial member, partial method, partial property, partial indexer,
510513
CS0260, CS0261, CS0262, CS0263, CS0264, CS0265, CS0267, CS0282, CS0501, CS0750, CS0751, CS0754, CS0755, CS0756, CS0757,
511514
CS0759, CS0761, CS0762, CS0763, CS0764, CS1067, CS8142, CS8663, CS8795, CS8796, CS8797, CS8798, CS8799, CS8800, CS8817,
512515
CS8818, CS8863, CS8988, CS9248, CS9249, CS9250, CS9251, CS9252, CS9253, CS9254, CS9255, CS9256, CS9257, CS9258, CS9263,
513-
CS9264, CS9266
516+
CS9264, CS9266, CS9273, CS9275, CS9276, CS9277, CS9278, CS9279, CS9280
514517
- name: Params modifier
515518
href: ./compiler-messages/params-arrays.md
516519
displayName: >
517-
CS0225, CS0231, CS0466, CS0674, CS0758, CS1104, CS1611, CS1670, CS1751, CS9218, CS9223, CS9224, CS9225, CS9227, CS9228
520+
CS0225, CS0231, CS0466, CS0674, CS0758, CS1104, CS1611, CS1670, CS1751, CS9218, CS9223, CS9224, CS9225, CS9227, CS9228,
521+
CS9272
518522
- name: Nullable warnings
519523
href: ./compiler-messages/nullable-warnings.md
520524
displayName: >
@@ -525,6 +529,9 @@ items:
525529
- name: Pattern matching warnings
526530
href: ./compiler-messages/pattern-matching-warnings.md
527531
displayName: CS8509, CS9134, CS9135
532+
- name: String literal declarations
533+
href: ./compiler-messages/string-literal-errors.md
534+
displayName: CS9274
528535
- name: Array declarations
529536
href: ./compiler-messages/array-declaration-errors.md
530537
displayName: >

docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -622,14 +622,6 @@ f1_keywords:
622622
- "CS9235"
623623
- "CS9236"
624624
# C# 14 errors begin here
625-
- "CS9273"
626-
- "CS9274"
627-
- "CS9275"
628-
- "CS9276"
629-
- "CS9277"
630-
- "CS9278"
631-
- "CS9279"
632-
- "CS9280"
633625
- "CS9281"
634626
- "CS9282"
635627
- "CS9283"

0 commit comments

Comments
 (0)