From 89d037075baed4df18ddf27dbb7ae28d8d7186ac Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Tue, 23 Jan 2024 17:22:52 +0100 Subject: [PATCH 1/2] update --- .../DisposeResourceAsynchronouslyAnalyzer.cs | 4 ++++ ...S1261DisposeResourceAsynchronouslyTests.cs | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Analyzers/CSharp/Analysis/DisposeResourceAsynchronouslyAnalyzer.cs b/src/Analyzers/CSharp/Analysis/DisposeResourceAsynchronouslyAnalyzer.cs index 5f8e4c9a50..c16ef55ab7 100644 --- a/src/Analyzers/CSharp/Analysis/DisposeResourceAsynchronouslyAnalyzer.cs +++ b/src/Analyzers/CSharp/Analysis/DisposeResourceAsynchronouslyAnalyzer.cs @@ -107,6 +107,10 @@ private static void Analyze(SyntaxNodeAnalysisContext context, StatementSyntax s Analyze(context, anonymousMethod.Modifiers, usingKeyword, anonymousMethod); break; } + else if (node is LockStatementSyntax) + { + return; + } } } diff --git a/src/Tests/Analyzers.Tests/RCS1261DisposeResourceAsynchronouslyTests.cs b/src/Tests/Analyzers.Tests/RCS1261DisposeResourceAsynchronouslyTests.cs index 16dc44028b..f116aaa175 100644 --- a/src/Tests/Analyzers.Tests/RCS1261DisposeResourceAsynchronouslyTests.cs +++ b/src/Tests/Analyzers.Tests/RCS1261DisposeResourceAsynchronouslyTests.cs @@ -919,6 +919,30 @@ internal class Disposable : IDisposable, IAsyncDisposable public void Dispose() => throw new NotImplementedException(); public ValueTask DisposeAsync() => throw new NotImplementedException(); } +"); + } + + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.DisposeResourceAsynchronously)] + public async Task TestNoDiagnostic_LockStatement() + { + await VerifyNoDiagnosticAsync(@" +using System.IO; +using System.Threading.Tasks; + +abstract class C +{ + object _lock = new(); + + async Task Foo() + { + lock (_lock) + { + using FileStream fs = new(""test.txt"", FileMode.OpenOrCreate); + } + + await Task.Yield(); + } +} "); } } From 78a745d0149135694a73a6eba26b8976b1c6198f Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Tue, 23 Jan 2024 17:23:50 +0100 Subject: [PATCH 2/2] update --- ChangeLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.md b/ChangeLog.md index 577feddf89..7ac863a75c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fix analyzer [RCS1055](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1055) ([PR](https://github.com/dotnet/roslynator/pull/1361)) +- Fix analyzer [RCS1261](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1261) ([PR](https://github.com/dotnet/roslynator/pull/1374)) ## [4.9.0] - 2024-01-10