Skip to content

Commit 42bbd9e

Browse files
committed
Add, update messages in dotnet/roslyn#73567
The PR for `ref struct` interfaces added new compiler error and warning messages. It also updates a few messages. This commit creates the stubs for the new messages, and updates the text for updated messages.
1 parent d3ed2ec commit 42bbd9e

File tree

6 files changed

+54
-8
lines changed

6 files changed

+54
-8
lines changed

docs/csharp/language-reference/compiler-messages/feature-version-errors.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ f1_keywords:
5353
- "CS9194"
5454
- "CS9202"
5555
- "CS9211"
56+
- "CS9240"
5657
helpviewer_keywords:
5758
- "CS0171"
5859
- "CS0188"
@@ -105,6 +106,7 @@ helpviewer_keywords:
105106
- "CS9194"
106107
- "CS9202"
107108
- "CS9211"
109+
- "CS9240"
108110
ms.date: 11/02/2023
109111
---
110112
# Resolve warnings related to language features and versions
@@ -146,6 +148,7 @@ That's be design. The text closely matches the text of the compiler error / warn
146148
- **CS9194**: *Argument may not be passed with the `ref` keyword. To pass `ref` arguments to `in` parameters, upgrade to language version 12 or greater.*
147149
- **CS9202**: *Feature is not available in C# 12.0. Please use newer language version*
148150
- **CS9211**: *The diagnosticId argument to the 'Experimental' attribute must be a valid identifier.*
151+
- **CS9240**: *Target runtime doesn't support by-ref-like generics.*
149152

150153
In addition, the following errors and warnings relate to struct initialization changes in recent versions:
151154

docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ That's by design. The text closely matches the text of the compiler error / warn
183183
- [**CS9078**](#ref-safety-violations): *Cannot return by reference a member of parameter through a `ref` parameter; it can only be returned in a return statement*
184184
- [**CS9079**](#ref-safety-violations): *Cannot ref-assign because source can only escape the current method through a return statement.*
185185
- [**CS9096**](#ref-safety-violations): *Cannot ref-assign because source has a wider value escape scope than destination allowing assignment through source of values with narrower escapes scopes than destination.*
186-
- [**CS9101**](#unscoped-ref-restrictions): *UnscopedRefAttribute can only be applied to struct instance methods and properties, and cannot be applied to constructors or init-only members.*
187-
- [**CS9102**](#unscoped-ref-restrictions): *UnscopedRefAttribute cannot be applied to an interface implementation.*
186+
- [**CS9101**](#unscoped-ref-restrictions): *UnscopedRefAttribute can only be applied to struct or virtual interface instance methods and properties, and cannot be applied to constructors or init-only members.*
187+
- [**CS9102**](#unscoped-ref-restrictions): *UnscopedRefAttribute cannot be applied to an interface implementation because implemented member doesn't have this attribute.*
188188
- [**CS9104**](#reference-variable-restrictions): *A `using` statement resource of type cannot be used in async methods or async lambda expressions.*
189189
- [**CS9190**](#incorrect-syntax): *`readonly` modifier must be specified after `ref`.*
190190
- [**CS9199**](#reference-variable-restrictions): *A `ref readonly` parameter cannot have the Out attribute.*
@@ -285,8 +285,8 @@ To fix the error, remove the reference variable where it isn't allowed:
285285

286286
The `unscoped` qualifier on `ref` parameters isn't allowed in some locations:
287287

288-
- **CS9101**: *UnscopedRefAttribute can only be applied to struct instance methods and properties, and cannot be applied to constructors or or init-only members.*
289-
- **CS9102**: *UnscopedRefAttribute cannot be applied to an interface implementation.*
288+
- **CS9101**: *UnscopedRefAttribute can only be applied to struct instance or virtual interface methods and properties, and cannot be applied to constructors or or init-only members.*
289+
- **CS9102**: *UnscopedRefAttribute cannot be applied to an interface implementation because implemented member doesn't have this attribute..*
290290

291291
You must remove the `unscoped` modifier on the parameter declaration that caused the error.
292292

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: Errors and warnings associated with `ref struct` types
3+
description: Learn about errors and warnings related to `ref struct` types. The compiler enforces several restrictions on `ref struct` types to enforce ref safety rules
4+
f1_keywords:
5+
- "CS8343"
6+
- "CS8344"
7+
- "CS9241"
8+
- "CS9242"
9+
- "CS9243"
10+
- "CS9244"
11+
- "CS9245"
12+
- "CS9246"
13+
- "CS9247"
14+
helpviewer_keywords:
15+
- "CS8343"
16+
- "CS8344"
17+
- "CS9241"
18+
- "CS9242"
19+
- "CS9243"
20+
- "CS9244"
21+
- "CS9245"
22+
- "CS9246"
23+
- "CS9247"
24+
ms.date: 07/30/2024
25+
---
26+
# Errors and warnings associated with reference parameters, variables, and returns
27+
28+
- [**CS8343**](#ref-struct-interface-implementations): *`ref structs` cannot implement interfaces*
29+
- [**CS8344**](#ref-struct-interface-implementations): *`foreach` statement cannot operate on enumerators in async or iterator methods because type is a `ref struct` or a type parameter that allows `ref struct`.*
30+
- [**CS9241**](#ref-struct-interface-implementations): *'ref struct' is already specified.*
31+
- [**CS9242**](#ref-struct-interface-implementations): *The 'allows' constraint clause must be the last constraint specified.*
32+
- [**CS9243**](#ref-struct-interface-implementations): *Cannot allow ref structs for a type parameter known from other constraints to be a class.*
33+
- [**CS9244**](#ref-struct-interface-implementations): *The type may not be a `ref struct` or a type parameter allowing ref structs in order to use it as parameter in the generic type or method.*
34+
- [**CS9245**](#ref-struct-interface-implementations): *Type cannot implement interface member for `ref struct` type.*
35+
- [**CS9246**](#ref-struct-interface-implementations): *A non-virtual instance interface member cannot be accessed on a type parameter that allows ref struct.*
36+
- [**CS9247**](#ref-struct-interface-implementations): *foreach statement cannot operate on enumerators of type '{0}' because it is a type parameter that allows ref struct and it is not known at compile time to implement IDisposable.*
37+
38+
## ref struct interface implementations
39+
40+
More content here.

docs/csharp/language-reference/toc.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ items:
437437
CS0171, CS0188, CS0843, CS8904, CS1738, CS8022, CS8023, CS8024, CS8025, CS8026, CS8058, CS8059, CS8107, CS8192, CS8302,
438438
CS8303, CS8304, CS8305, CS8306, CS8314, CS8320, CS8370, CS8371, CS8400, CS8401, CS8511, CS8627, CS8630, CS8652, CS8703,
439439
CS8704, CS8706, CS8773, CS8912, CS8919, CS8929, CS8936, CS8957, CS8967, CS9014, CS9015, CS9016, CS9017, CS9058, CS9064,
440-
CS9103, CS9171, CS9194, CS9202, CS9204
440+
CS9103, CS9171, CS9194, CS9202, CS9204, CS9240
441441
- name: Assembly references
442442
href: ./compiler-messages/assembly-references.md
443443
displayName: >
@@ -464,6 +464,11 @@ items:
464464
CS8351, CS8373, CS8374, CS8388, CS8977, CS9072, CS9077, CS9078, CS9079, CS9085, CS9086, CS9087, CS9089, CS9091, CS9092,
465465
CS9093, CS9094, CS9095, CS9096, CS9097, CS9101, CS9102, CS9104, CS9190, CS9191, CS9192, CS9193, CS9195, CS9196, CS9197,
466466
CS9198, CS9199, CS9200, CS9201
467+
- name: "`ref struct` types"
468+
href: ./compiler-messages/ref-struct-errors.md
469+
displayName: >
470+
ref struct,
471+
CS8343, CS8344, CS9241, CS9242, CS9243, CS9244, CS9245, CS9246, CS9247
467472
- name: Iterator methods
468473
href: ./compiler-messages/iterator-yield.md
469474
displayName: >

docs/csharp/misc/cs0401.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ms.assetid: 94eac5a8-7344-44d2-9d0c-a9954993603d
1010
---
1111
# Compiler Error CS0401
1212

13-
The new() constraint must be the last constraint specified
13+
The new() constraint must be the last restrictive constraint specified
1414

1515
When using multiple constraints, list all other constraints before the new() constraint.
1616

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,6 @@ f1_keywords:
304304
- "CS8340"
305305
- "CS8341"
306306
- "CS8342"
307-
- "CS8343"
308-
- "CS8344"
309307
- "CS8346"
310308
- "CS8347"
311309
- "CS8348"

0 commit comments

Comments
 (0)