Skip to content

Commit f872c9d

Browse files
committed
Handle ValuEtASK
fix #470
1 parent 69035d7 commit f872c9d

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

IDisposableAnalyzers.Test/IDISP001DisposeCreatedTests/Valid.Returned.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,42 @@ public void Dispose()
404404
RoslynAssert.Valid(Analyzer, Disposable, code);
405405
}
406406

407+
[Test]
408+
public static void ReturnInValueTask()
409+
{
410+
var disposable = """
411+
412+
namespace N;
413+
414+
using System;
415+
416+
public class Disposable : IDisposable
417+
{
418+
public void Dispose()
419+
{
420+
}
421+
}
422+
""";
423+
424+
var code = """
425+
426+
namespace N;
427+
428+
using System;
429+
using System.Threading.Tasks;
430+
431+
public class C
432+
{
433+
public ValueTask<IDisposable> M()
434+
{
435+
var disposable = new Disposable();
436+
return new ValueTask<IDisposable>(disposable);
437+
}
438+
}
439+
""";
440+
RoslynAssert.Valid(Analyzer, disposable, code);
441+
}
442+
407443
[Test]
408444
public static void LocalFunctionStatementBody()
409445
{

IDisposableAnalyzers/Helpers/Disposable.Identity.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ parameter.ContainingSymbol is IMethodSymbol extensionMethod
3131
{ Parent: ArgumentSyntax { Parent: ArgumentListSyntax { Parent: InvocationExpressionSyntax { Expression: MemberAccessExpressionSyntax { Name: IdentifierNameSyntax { Identifier.ValueText: "FromResult" } } } invocation } } }
3232
when invocation.IsSymbol(KnownSymbols.Task.FromResult, recursion.SemanticModel, recursion.CancellationToken)
3333
=> Recursive(invocation, recursion),
34+
{ Parent: ArgumentSyntax { Parent: ArgumentListSyntax { Parent: ObjectCreationExpressionSyntax { } objectCreation } } }
35+
when objectCreation.IsType(KnownSymbols.ValueTaskOfT, recursion.SemanticModel, recursion.CancellationToken)
36+
=> Recursive(objectCreation, recursion),
3437
{ Parent: ArgumentSyntax { Parent: ArgumentListSyntax { Parent: InvocationExpressionSyntax invocation } } argument }
3538
when recursion.Target(argument) is { } target &&
3639
IsIdentity(target, recursion)

0 commit comments

Comments
 (0)