Skip to content

Commit afbcf7a

Browse files
BoukeJohanLarsson
authored andcommitted
Fix IDISP013 using declaration in outer scope regression
1 parent b864e75 commit afbcf7a

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

IDisposableAnalyzers.Test/IDISP013AwaitInUsingTests/Diagnostics.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,35 @@ private static async ValueTask<int> InnerAsync()
8686
RoslynAssert.Diagnostics(Analyzer, ExpectedDiagnostic, code);
8787
}
8888

89+
[Test]
90+
public static void UsingDeclarationInner()
91+
{
92+
var code = @"
93+
namespace N
94+
{
95+
using System.Threading.Tasks;
96+
97+
public static class C
98+
{
99+
public static ValueTask<int> MAsync()
100+
{
101+
using var file = System.IO.File.OpenRead(string.Empty);
102+
while (true)
103+
{
104+
return ↓InnerAsync();
105+
}
106+
}
107+
108+
private static async ValueTask<int> InnerAsync()
109+
{
110+
await Task.Delay(10).ConfigureAwait(false);
111+
return 1;
112+
}
113+
}
114+
}";
115+
RoslynAssert.Diagnostics(Analyzer, ExpectedDiagnostic, code);
116+
}
117+
89118
[Test]
90119
public static void LocalTask()
91120
{

IDisposableAnalyzers/Analyzers/ReturnValueAnalyzer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,16 @@ private static bool IsInUsing(SyntaxNode node)
146146
{
147147
if (statement.SpanStart >= node.SpanStart)
148148
{
149-
return false;
149+
break;
150150
}
151151

152152
if (statement is LocalDeclarationStatementSyntax { UsingKeyword.ValueText: "using" })
153153
{
154154
return true;
155155
}
156156
}
157+
158+
return node.Parent != null && IsInUsing(node.Parent);
157159
}
158160

159161
return false;

0 commit comments

Comments
 (0)