From 7fa3cde185e702577ca69b011430f91ea6e3255e Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Mon, 24 Jun 2024 12:01:58 +0200 Subject: [PATCH] Remove warning for `yield return` in `lock` (#74024) * Remove warning for `yield return` in `lock` * Remove WithWarningLevel --- .../CSharp/Warnversion Warning Waves.md | 8 ---- .../Portable/Binder/Binder_Statements.cs | 5 --- .../CSharp/Portable/CSharpResources.resx | 6 --- .../CSharp/Portable/Errors/ErrorCode.cs | 2 +- .../CSharp/Portable/Errors/ErrorFacts.cs | 5 --- .../Generated/ErrorFacts.Generated.cs | 1 - .../Portable/xlf/CSharpResources.cs.xlf | 10 ----- .../Portable/xlf/CSharpResources.de.xlf | 10 ----- .../Portable/xlf/CSharpResources.es.xlf | 10 ----- .../Portable/xlf/CSharpResources.fr.xlf | 10 ----- .../Portable/xlf/CSharpResources.it.xlf | 10 ----- .../Portable/xlf/CSharpResources.ja.xlf | 10 ----- .../Portable/xlf/CSharpResources.ko.xlf | 10 ----- .../Portable/xlf/CSharpResources.pl.xlf | 10 ----- .../Portable/xlf/CSharpResources.pt-BR.xlf | 10 ----- .../Portable/xlf/CSharpResources.ru.xlf | 10 ----- .../Portable/xlf/CSharpResources.tr.xlf | 10 ----- .../Portable/xlf/CSharpResources.zh-Hans.xlf | 10 ----- .../Portable/xlf/CSharpResources.zh-Hant.xlf | 10 ----- .../EditAndContinueStateMachineTests.cs | 5 +-- .../CSharp/Test/Emit2/Semantics/LockTests.cs | 10 +---- .../Test/Semantic/Semantics/IteratorTests.cs | 37 ++----------------- .../Test/Syntax/Diagnostics/DiagnosticTest.cs | 4 -- 23 files changed, 7 insertions(+), 206 deletions(-) diff --git a/docs/compilers/CSharp/Warnversion Warning Waves.md b/docs/compilers/CSharp/Warnversion Warning Waves.md index f80c80e658838..65d25e8b1b528 100644 --- a/docs/compilers/CSharp/Warnversion Warning Waves.md +++ b/docs/compilers/CSharp/Warnversion Warning Waves.md @@ -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. diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs index 2c3e5f1316a56..4c34e43f527fc 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs @@ -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); diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 4afce6fc3e0b4..4bbab9340238f 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -7896,12 +7896,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ The data argument to InterceptsLocationAttribute refers to an invalid position in file '{0}'. - - 'yield return' should not be used in the body of a lock statement - - - 'yield return' should not be used in the body of a lock statement - ref and unsafe in async and iterator methods diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index de2c2675c12f6..cb49b23a97735 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -2312,7 +2312,7 @@ internal enum ErrorCode #endregion - WRN_BadYieldInLock = 9237, + // available 9237 ERR_BadYieldInUnsafe = 9238, ERR_AddressOfInIterator = 9239, diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs index 5410428440fee..924e7c93d8ed5 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs @@ -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 @@ -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 diff --git a/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs b/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs index 7c0efab349716..23ef65e70688e 100644 --- a/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs +++ b/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs @@ -338,7 +338,6 @@ public static bool IsWarning(ErrorCode code) case ErrorCode.WRN_CollectionExpressionRefStructMayAllocate: case ErrorCode.WRN_CollectionExpressionRefStructSpreadMayAllocate: case ErrorCode.WRN_ConvertingLock: - case ErrorCode.WRN_BadYieldInLock: case ErrorCode.WRN_PartialPropertySignatureDifference: return true; default: diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index 22a63970c11b5..bac5870d78f08 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -2707,16 +2707,6 @@ Modifikátor ref pro argument odpovídající parametru in je ekvivalentem in. Místo toho zvažte použití in. - - 'yield return' should not be used in the body of a lock statement - Příkaz yield return by se neměl používat v těle výrazu lock. - - - - 'yield return' should not be used in the body of a lock statement - Příkaz yield return by se neměl používat v těle výrazu lock. - - Attribute parameter 'SizeConst' must be specified. Je nutné zadat parametr atributu SizeConst. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 5de3db4659b98..44b905d4f115a 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -2707,16 +2707,6 @@ Der ref-Modifizierer für ein Argument, das dem in-Parameter entspricht, entspricht "in". Erwägen Sie stattdessen die Verwendung von "in". - - 'yield return' should not be used in the body of a lock statement - „yield return“ darf nicht im Text einer lock-Anweisung verwendet werden. - - - - 'yield return' should not be used in the body of a lock statement - „yield return“ darf nicht im Text einer lock-Anweisung verwendet werden. - - Attribute parameter 'SizeConst' must be specified. Der Attributparameter "SizeConst" muss angegeben werden. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 71f932d452ffd..3c5668d35dad2 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -2707,16 +2707,6 @@ El modificador "ref" de un argumento correspondiente al parámetro "in" es equivalente a "in". Considere la posibilidad de usar "in" en su lugar. - - 'yield return' should not be used in the body of a lock statement - "yield return" no se debe usar en el cuerpo de una instrucción lock - - - - 'yield return' should not be used in the body of a lock statement - "yield return" no se debe usar en el cuerpo de una instrucción lock - - Attribute parameter 'SizeConst' must be specified. Se debe especificar el parámetro de atributo "SizeConst". diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index da68930843e1a..235b390c19fce 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -2707,16 +2707,6 @@ Le modificateur « ref » d’un argument correspondant au paramètre « in » est équivalent à « in ». Envisagez d’utiliser « in » à la place. - - 'yield return' should not be used in the body of a lock statement - une instruction « yield return » ne doit pas être utilisée dans le corps d’une instruction lock - - - - 'yield return' should not be used in the body of a lock statement - une instruction « yield return » ne doit pas être utilisée dans le corps d’une instruction lock - - Attribute parameter 'SizeConst' must be specified. Vous devez spécifier un paramètre d’attribut « SizeConst ». diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index c5ff90fb83eaa..f3f95072912ee 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -2707,16 +2707,6 @@ Il modificatore 'ref' per un argomento corrispondente al parametro 'in' equivale a 'in'. Provare a usare 'in'. - - 'yield return' should not be used in the body of a lock statement - 'yield return' non deve essere usato nel corpo di un'istruzione lock - - - - 'yield return' should not be used in the body of a lock statement - 'yield return' non deve essere usato nel corpo di un'istruzione lock - - Attribute parameter 'SizeConst' must be specified. È necessario specificare il parametro di attributo 'SizeConst'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 0e1a13c66f483..acd69461b17b7 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -2707,16 +2707,6 @@ 'in' パラメーターに対応する引数の 'ref' 修飾子は 'in' と同じです。代わりに 'in' を使用することを検討してください。 - - 'yield return' should not be used in the body of a lock statement - 'yield return' は、lock ステートメント本体では使用できません - - - - 'yield return' should not be used in the body of a lock statement - 'yield return' は、lock ステートメント本体では使用できません - - Attribute parameter 'SizeConst' must be specified. 属性パラメーター 'SizeConst' を指定する必要があります。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index 5e53b9ec082c8..01e14d10f8b86 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -2707,16 +2707,6 @@ 'in' 매개 변수에 해당하는 인수의 'ref' 한정자는 'in'에 해당합니다. 대신 'in'을 사용하는 것이 좋습니다. - - 'yield return' should not be used in the body of a lock statement - 'yield return'은 lock 문의 본문에 사용해서는 안 됩니다. - - - - 'yield return' should not be used in the body of a lock statement - 'yield return'은 lock 문의 본문에 사용해서는 안 됩니다. - - Attribute parameter 'SizeConst' must be specified. 특성 매개 변수 'SizeConst'를 지정해야 합니다. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index 4ce05d81b7fb3..3785102adab17 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -2707,16 +2707,6 @@ Modyfikator „ref” dla argumentu odpowiadającego parametrowi „in” jest równoważny parametrowi „in”. Zamiast tego rozważ użycie parametru „in”. - - 'yield return' should not be used in the body of a lock statement - Instrukcja „yield return” nie powinna być używana w treści instrukcji lock - - - - 'yield return' should not be used in the body of a lock statement - Instrukcja „yield return” nie powinna być używana w treści instrukcji lock - - Attribute parameter 'SizeConst' must be specified. Należy określić parametr atrybutu „SizeConst”. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index acb57236af4d1..5fd2013b34589 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -2707,16 +2707,6 @@ O modificador 'ref' do argumento correspondente ao parâmetro 'in' é equivalente a 'in'. Considere usar 'in' em vez disso. - - 'yield return' should not be used in the body of a lock statement - "yield return" não deve ser usado no corpo de uma instrução de bloqueio - - - - 'yield return' should not be used in the body of a lock statement - "yield return" não deve ser usado no corpo de uma instrução de bloqueio - - Attribute parameter 'SizeConst' must be specified. O parâmetro de atribuição 'SizeConst' deve ser especificado. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index 3f214530c7e62..8d4ad954bd6e7 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -2707,16 +2707,6 @@ Модификатор "ref" для аргумента, соответствующего параметру "in", эквивалентен "in". Попробуйте вместо этого использовать "in". - - 'yield return' should not be used in the body of a lock statement - "yield return" не следует использовать в тексте оператора блокировки. - - - - 'yield return' should not be used in the body of a lock statement - "yield return" не следует использовать в тексте оператора блокировки. - - Attribute parameter 'SizeConst' must be specified. Должен быть указан параметр атрибута "SizeConst". diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index b973cb5f1aed9..9826697969aa0 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -2707,16 +2707,6 @@ 'in' parametresine karşılık gelen bir bağımsız değişken için 'ref' değiştiricisi 'in' ile eşdeğerdir. Bunun yerine 'in' kullanmayı düşünün. - - 'yield return' should not be used in the body of a lock statement - 'yield return' bir kilit deyiminin gövdesinde kullanılamaz - - - - 'yield return' should not be used in the body of a lock statement - 'yield return' bir kilit deyiminin gövdesinde kullanılamaz - - Attribute parameter 'SizeConst' must be specified. 'SizeConst' öznitelik parametresi belirtilmelidir. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index 79b66906d04ac..e6e5528e20b07 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -2707,16 +2707,6 @@ 与 “in” 参数对应的参数的 “ref” 修饰符等效于 “in”。请考虑改用 “in”。 - - 'yield return' should not be used in the body of a lock statement - 不应在 lock 语句体中使用 "yield return" - - - - 'yield return' should not be used in the body of a lock statement - 不应在 lock 语句体中使用 "yield return" - - Attribute parameter 'SizeConst' must be specified. 必须指定属性参数 “SizeConst”。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index ad24091a858da..d14cb40168a2c 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -2707,16 +2707,6 @@ 對應至 'in' 參數之引數的 'ref' 修飾元相當於 'in'。請考慮改為使用 'in'。 - - 'yield return' should not be used in the body of a lock statement - 'yield return' 不得用於鎖定陳述式的本文中 - - - - 'yield return' should not be used in the body of a lock statement - 'yield return' 不得用於鎖定陳述式的本文中 - - Attribute parameter 'SizeConst' must be specified. 必須指定屬性參數 'SizeConst'。 diff --git a/src/Compilers/CSharp/Test/Emit2/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs b/src/Compilers/CSharp/Test/Emit2/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs index d2f3bf455c812..028ff1e8ff7d4 100644 --- a/src/Compilers/CSharp/Test/Emit2/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs +++ b/src/Compilers/CSharp/Test/Emit2/Emit/EditAndContinue/EditAndContinueStateMachineTests.cs @@ -5463,10 +5463,7 @@ static IEnumerable 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("C.F"); diff --git a/src/Compilers/CSharp/Test/Emit2/Semantics/LockTests.cs b/src/Compilers/CSharp/Test/Emit2/Semantics/LockTests.cs index 61614ef54b64e..8152696154ca1 100644 --- a/src/Compilers/CSharp/Test/Emit2/Semantics/LockTests.cs +++ b/src/Compilers/CSharp/Test/Emit2/Semantics/LockTests.cs @@ -3448,10 +3448,7 @@ IEnumerable M() CreateCompilation([source, LockTypeDefinition]).VerifyEmitDiagnostics( // (9,15): error CS4007: Instance of type 'System.Threading.Lock.Scope' cannot be preserved across 'await' or 'yield' boundary. // lock (new Lock()) - Diagnostic(ErrorCode.ERR_ByRefTypeAndAwait, "new Lock()").WithArguments("System.Threading.Lock.Scope").WithLocation(9, 15), - // (11,13): warning CS9237: 'yield return' should not be used in the body of a lock statement - // yield return 2; - Diagnostic(ErrorCode.WRN_BadYieldInLock, "yield").WithLocation(11, 13)); + Diagnostic(ErrorCode.ERR_ByRefTypeAndAwait, "new Lock()").WithArguments("System.Threading.Lock.Scope").WithLocation(9, 15)); } [Fact] @@ -3560,10 +3557,7 @@ async IAsyncEnumerable M() CreateCompilationWithTasksExtensions([source, LockTypeDefinition, AsyncStreamsTypes]).VerifyEmitDiagnostics( // (10,15): error CS4007: Instance of type 'System.Threading.Lock.Scope' cannot be preserved across 'await' or 'yield' boundary. // lock (new Lock()) - Diagnostic(ErrorCode.ERR_ByRefTypeAndAwait, "new Lock()").WithArguments("System.Threading.Lock.Scope").WithLocation(10, 15), - // (12,13): warning CS9237: 'yield return' should not be used in the body of a lock statement - // yield return 2; - Diagnostic(ErrorCode.WRN_BadYieldInLock, "yield").WithLocation(12, 13)); + Diagnostic(ErrorCode.ERR_ByRefTypeAndAwait, "new Lock()").WithArguments("System.Threading.Lock.Scope").WithLocation(10, 15)); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/IteratorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/IteratorTests.cs index 06055448cc8b6..2a447bcca3b67 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/IteratorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/IteratorTests.cs @@ -144,21 +144,8 @@ private async IAsyncEnumerable GetValuesAsync() } """ + AsyncStreamsTypes; - var comp = CreateCompilationWithTasksExtensions(source, options: TestOptions.ReleaseDll.WithWarningLevel(8)); + var comp = CreateCompilationWithTasksExtensions(source); CompileAndVerify(comp).VerifyDiagnostics(); - - var expectedDiagnostics = new[] - { - // (23,17): warning CS9237: 'yield return' should not be used in the body of a lock statement - // yield return i; - Diagnostic(ErrorCode.WRN_BadYieldInLock, "yield").WithLocation(23, 17) - }; - - comp = CreateCompilationWithTasksExtensions(source, options: TestOptions.ReleaseDll.WithWarningLevel(9)); - CompileAndVerify(comp).VerifyDiagnostics(expectedDiagnostics); - - comp = CreateCompilationWithTasksExtensions(source, options: TestOptions.ReleaseDll); - CompileAndVerify(comp).VerifyDiagnostics(expectedDiagnostics); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/72443")] @@ -208,20 +195,8 @@ static IEnumerable GetValues(object obj) After: False """; - CompileAndVerify(source, options: TestOptions.ReleaseExe.WithWarningLevel(8), + CompileAndVerify(source, options: TestOptions.ReleaseExe, expectedOutput: expectedOutput).VerifyDiagnostics(); - - var expectedDiagnostics = new[] - { - // (24,13): warning CS9237: 'yield return' should not be used in the body of a lock statement - // yield return i; - Diagnostic(ErrorCode.WRN_BadYieldInLock, "yield").WithLocation(24, 13) - }; - - CompileAndVerify(source, options: TestOptions.ReleaseExe.WithWarningLevel(9), - expectedOutput: expectedOutput).VerifyDiagnostics(expectedDiagnostics); - - CompileAndVerify(source, expectedOutput: expectedOutput).VerifyDiagnostics(expectedDiagnostics); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/72443")] @@ -259,13 +234,7 @@ IEnumerable local() } """; - CreateCompilation(source).VerifyDiagnostics( - // (10,13): warning CS9237: 'yield return' should not be used in the body of a lock statement - // yield return 2; - Diagnostic(ErrorCode.WRN_BadYieldInLock, "yield").WithLocation(10, 13), - // (20,21): warning CS9237: 'yield return' should not be used in the body of a lock statement - // yield return 4; - Diagnostic(ErrorCode.WRN_BadYieldInLock, "yield").WithLocation(20, 21)); + CreateCompilation(source).VerifyDiagnostics(); } [WorkItem(546081, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546081")] diff --git a/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs b/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs index 2aa8fdc21c6f1..a196defc664ea 100644 --- a/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs +++ b/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs @@ -470,10 +470,6 @@ public void WarningLevel_2() // These are the warnings introduced with the warning "wave" shipped with dotnet 8 and C# 12. Assert.Equal(8, ErrorFacts.GetWarningLevel(errorCode)); break; - case ErrorCode.WRN_BadYieldInLock: - // These are the warnings introduced with the warning "wave" shipped with dotnet 9 and C# 13. - Assert.Equal(9, ErrorFacts.GetWarningLevel(errorCode)); - break; default: // If a new warning is added, this test will fail // and whoever is adding the new warning will have to update it with the expected error level.