Skip to content

Commit 6cc8019

Browse files
authored
Allow yield return in lock (#43988)
* Allow `yield return` in `lock` * Remove lock statement restriction from iterator yield
1 parent 469b13a commit 6cc8019

File tree

1 file changed

+0
-5
lines changed

1 file changed

+0
-5
lines changed

docs/csharp/language-reference/compiler-messages/iterator-yield.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ f1_keywords:
1313
- "CS4013"
1414
- "CS8154"
1515
- "CS8176"
16-
- "CS9237"
1716
- "CS9238"
1817
- "CS9239"
1918
helpviewer_keywords:
@@ -28,7 +27,6 @@ helpviewer_keywords:
2827
- "CS4013"
2928
- "CS8154"
3029
- "CS8176"
31-
- "CS9237"
3230
- "CS9238"
3331
- "CS9239"
3432
ms.date: 07/02/2024
@@ -51,7 +49,6 @@ That's by design. The text closely matches the text of the compiler error / warn
5149
- [**CS4013**](#ref-safety-in-iterator-methods): *Instance of type cannot be used inside a nested function, query expression, iterator block or async method*
5250
- [**CS8154**](#structure-of-an-iterator-method): *The body cannot be an iterator block because it returns by reference*
5351
- [**CS8176**](#ref-safety-in-iterator-methods): *Iterators cannot have by-reference locals*
54-
- [**CS9237**](#restrictions-on-iterator-methods): *'yield return' should not be used in the body of a lock statement*
5552
- [**CS9238**](#restrictions-on-iterator-methods): *Cannot use 'yield return' in an 'unsafe' block*
5653
- [**CS9239**](#restrictions-on-iterator-methods): *The `&` operator cannot be used on parameters or local variables in iterator methods.*
5754

@@ -82,15 +79,13 @@ The body of an iterator method must conform to restrictions on the `yield return
8279
- **CS1626**: *Cannot yield a value in the body of a try block with a catch clause*
8380
- **CS1631**: *Cannot yield a value in the body of a catch clause*
8481
- **CS1629**: *Unsafe code may not appear in iterators*
85-
- **CS9237**: *''yield return' should not be used in the body of a lock statement*
8682
- **CS9238**: *Cannot use 'yield return' in an 'unsafe' block*
8783
- **CS9239**: *The `&` operator cannot be used on parameters or local variables in iterator methods.*
8884

8985
These errors indicate that your code violates safety rules because an iterator returns an element and resumes to generate the next element:
9086

9187
- You can't `yield return` from a `catch` or `finally` clause.
9288
- You can't `yield return` from a `try` block with a catch clause.
93-
- You can't `yield return` from inside a `lock` statement block. Doing so can cause deadlocks.
9489
- You can't `yield return` from an `unsafe` block. The context for an iterator creates a nested `safe` block within the enclosing `unsafe` block.
9590
- You can't use the `&` operator to take the address of a variable in an iterator method.
9691

0 commit comments

Comments
 (0)