File tree Expand file tree Collapse file tree
IDisposableAnalyzers.Test/IDISP001DisposeCreatedTests
IDisposableAnalyzers/Helpers Expand file tree Collapse file tree Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments