Skip to content

Commit c00eeba

Browse files
committed
Remove warning for yield return in lock
1 parent 9d5e375 commit c00eeba

23 files changed

+6
-205
lines changed

docs/compilers/CSharp/Warnversion Warning Waves.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ In a typical project, this setting is controlled by the `AnalysisLevel` property
1313
which determines the `WarningLevel` property (passed to the `Csc` task).
1414
For more information on `AnalysisLevel`, see https://devblogs.microsoft.com/dotnet/automatically-find-latent-bugs-in-your-code-with-net-5/
1515

16-
## Warning level 9
17-
18-
The compiler shipped with .NET 9 (the C# 13 compiler) contains the following warnings which are reported only under `/warn:9` or higher.
19-
20-
| Warning ID | Description |
21-
|------------|-------------|
22-
| CS9237 | ['yield return' should not be used in the body of a lock statement](https://github.com/dotnet/roslyn/issues/72443) |
23-
2416
## Warning level 8
2517

2618
The compiler shipped with .NET 8 (the C# 12 compiler) contains the following warnings which are reported only under `/warn:8` or higher.

src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,6 @@ private BoundStatement BindYieldReturnStatement(YieldStatementSyntax node, Bindi
270270
{
271271
Error(diagnostics, ErrorCode.ERR_BadYieldInUnsafe, node.YieldKeyword);
272272
}
273-
// NOTE: Error conditions should be checked above this point; only warning conditions below.
274-
else if (this.Flags.Includes(BinderFlags.InLockBody))
275-
{
276-
Error(diagnostics, ErrorCode.WRN_BadYieldInLock, node.YieldKeyword);
277-
}
278273

279274
CheckRequiredLangVersionForIteratorMethods(node, diagnostics);
280275
return new BoundYieldReturnStatement(node, argument);

src/Compilers/CSharp/Portable/CSharpResources.resx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7899,12 +7899,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
78997899
<data name="ERR_InterceptsLocationDataInvalidPosition" xml:space="preserve">
79007900
<value>The data argument to InterceptsLocationAttribute refers to an invalid position in file '{0}'.</value>
79017901
</data>
7902-
<data name="WRN_BadYieldInLock" xml:space="preserve">
7903-
<value>'yield return' should not be used in the body of a lock statement</value>
7904-
</data>
7905-
<data name="WRN_BadYieldInLock_Title" xml:space="preserve">
7906-
<value>'yield return' should not be used in the body of a lock statement</value>
7907-
</data>
79087902
<data name="IDS_FeatureRefUnsafeInIteratorAsync" xml:space="preserve">
79097903
<value>ref and unsafe in async and iterator methods</value>
79107904
</data>

src/Compilers/CSharp/Portable/Errors/ErrorCode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,7 @@ internal enum ErrorCode
23122312

23132313
#endregion
23142314

2315-
WRN_BadYieldInLock = 9237,
2315+
// available 9237
23162316
ERR_BadYieldInUnsafe = 9238,
23172317
ERR_AddressOfInIterator = 9239,
23182318

src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@ internal static int GetWarningLevel(ErrorCode code)
207207
// docs/compilers/CSharp/Warnversion Warning Waves.md
208208
switch (code)
209209
{
210-
case ErrorCode.WRN_BadYieldInLock:
211-
// Warning level 9 is exclusively for warnings introduced in the compiler
212-
// shipped with dotnet 9 (C# 13) and that can be reported for pre-existing code.
213-
return 9;
214210
case ErrorCode.WRN_AddressOfInAsync:
215211
case ErrorCode.WRN_ByValArraySizeConstRequired:
216212
// Warning level 8 is exclusively for warnings introduced in the compiler
@@ -2434,7 +2430,6 @@ or ErrorCode.ERR_InterceptsLocationDuplicateFile
24342430
or ErrorCode.ERR_InterceptsLocationFileNotFound
24352431
or ErrorCode.ERR_InterceptsLocationDataInvalidPosition
24362432
or ErrorCode.INF_TooManyBoundLambdas
2437-
or ErrorCode.WRN_BadYieldInLock
24382433
or ErrorCode.ERR_BadYieldInUnsafe
24392434
or ErrorCode.ERR_AddressOfInIterator
24402435
or ErrorCode.ERR_RuntimeDoesNotSupportByRefLikeGenerics

src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)