Skip to content

Commit

Permalink
Remove warning for yield return in lock (dotnet#74024)
Browse files Browse the repository at this point in the history
* Remove warning for `yield return` in `lock`

* Remove WithWarningLevel
  • Loading branch information
jjonescz committed Jun 24, 2024
1 parent 847d588 commit 7fa3cde
Show file tree
Hide file tree
Showing 23 changed files with 7 additions and 206 deletions.
8 changes: 0 additions & 8 deletions docs/compilers/CSharp/Warnversion Warning Waves.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ In a typical project, this setting is controlled by the `AnalysisLevel` property
which determines the `WarningLevel` property (passed to the `Csc` task).
For more information on `AnalysisLevel`, see https://devblogs.microsoft.com/dotnet/automatically-find-latent-bugs-in-your-code-with-net-5/

## Warning level 9

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

| Warning ID | Description |
|------------|-------------|
| CS9237 | ['yield return' should not be used in the body of a lock statement](https://github.com/dotnet/roslyn/issues/72443) |

## Warning level 8

The compiler shipped with .NET 8 (the C# 12 compiler) contains the following warnings which are reported only under `/warn:8` or higher.
Expand Down
5 changes: 0 additions & 5 deletions src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,6 @@ private BoundStatement BindYieldReturnStatement(YieldStatementSyntax node, Bindi
{
Error(diagnostics, ErrorCode.ERR_BadYieldInUnsafe, node.YieldKeyword);
}
// NOTE: Error conditions should be checked above this point; only warning conditions below.
else if (this.Flags.Includes(BinderFlags.InLockBody))
{
Error(diagnostics, ErrorCode.WRN_BadYieldInLock, node.YieldKeyword);
}

CheckRequiredLangVersionForIteratorMethods(node, diagnostics);
return new BoundYieldReturnStatement(node, argument);
Expand Down
6 changes: 0 additions & 6 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -7896,12 +7896,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_InterceptsLocationDataInvalidPosition" xml:space="preserve">
<value>The data argument to InterceptsLocationAttribute refers to an invalid position in file '{0}'.</value>
</data>
<data name="WRN_BadYieldInLock" xml:space="preserve">
<value>'yield return' should not be used in the body of a lock statement</value>
</data>
<data name="WRN_BadYieldInLock_Title" xml:space="preserve">
<value>'yield return' should not be used in the body of a lock statement</value>
</data>
<data name="IDS_FeatureRefUnsafeInIteratorAsync" xml:space="preserve">
<value>ref and unsafe in async and iterator methods</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2312,7 +2312,7 @@ internal enum ErrorCode

#endregion

WRN_BadYieldInLock = 9237,
// available 9237
ERR_BadYieldInUnsafe = 9238,
ERR_AddressOfInIterator = 9239,

Expand Down
5 changes: 0 additions & 5 deletions src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ internal static int GetWarningLevel(ErrorCode code)
// docs/compilers/CSharp/Warnversion Warning Waves.md
switch (code)
{
case ErrorCode.WRN_BadYieldInLock:
// Warning level 9 is exclusively for warnings introduced in the compiler
// shipped with dotnet 9 (C# 13) and that can be reported for pre-existing code.
return 9;
case ErrorCode.WRN_AddressOfInAsync:
case ErrorCode.WRN_ByValArraySizeConstRequired:
// Warning level 8 is exclusively for warnings introduced in the compiler
Expand Down Expand Up @@ -2433,7 +2429,6 @@ or ErrorCode.ERR_InterceptsLocationDuplicateFile
or ErrorCode.ERR_InterceptsLocationFileNotFound
or ErrorCode.ERR_InterceptsLocationDataInvalidPosition
or ErrorCode.INF_TooManyBoundLambdas
or ErrorCode.WRN_BadYieldInLock
or ErrorCode.ERR_BadYieldInUnsafe
or ErrorCode.ERR_AddressOfInIterator
or ErrorCode.ERR_RuntimeDoesNotSupportByRefLikeGenerics
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5463,10 +5463,7 @@ static IEnumerable<int> F()
var compilation1 = compilation0.WithSource(source1.Tree);

var v0 = CompileAndVerify(compilation0);
v0.VerifyDiagnostics(
// (17,34): warning CS9237: 'yield return' should not be used in the body of a lock statement
// yield return 1;
Diagnostic(ErrorCode.WRN_BadYieldInLock, "yield").WithLocation(17, 34));
v0.VerifyDiagnostics();
var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData);

var f0 = compilation0.GetMember<MethodSymbol>("C.F");
Expand Down
Loading

0 comments on commit 7fa3cde

Please sign in to comment.